|
-
Aug 6th, 2006, 01:08 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2005] Running a program with parameters
I'm trying to do the following:
VB Code:
Dim programparameters as string
openfiledialog.ShowOpen
Process.Start(openfiledialog.Filename & " " & programparameters)
but, as you would've guessed by now (hence why I am here) is that my program doesn't like it.
I've ommited the arguments, but further on in the code, I use Shell() command for running a program with arguments.
Is the Shell command the way to go, or is there a .NET way of doing what I've asked?
-
Aug 6th, 2006, 01:14 PM
#2
Re: [2005] Running a program with parameters
You can use the Process class in place of the Shell() command, like you were trying to do. The Process class has a StartInfo property where you can specify a StartInfo object, which gives you options to specify the filename and additional arguments to run. An example is below:
VB Code:
Dim MyProcess As New Process
Dim MyStartInfo As New ProcessStartInfo
'filename of the program to run, best to use full path
MyStartInfo.FileName = "notepad.exe"
'arguments to pass into the program
MyStartInfo.Arguments = "my arguments"
'sets new startinfo object to MyProcess' StartInfo property
MyProcess.StartInfo = MyStartInfo
'starts the process
MyProcess.Start()
Last edited by gigemboy; Aug 6th, 2006 at 01:19 PM.
-
Aug 6th, 2006, 07:50 PM
#3
Re: [2005] Running a program with parameters
Process.Start is overloaded and you should read the documentation to see how each overload works. If all you want to do is pass some commandline parameters to a new executable then the easiest way is:
VB Code:
Process.Start("file path", "arguments")
There are other alternatives too. Gig's is more complex than necessary because you don't have to create both Process and ProcessStartInfo objects. You would normally create either one or the other. That's because a Process object already has a ProcessStartInfo object associated with it, and if you start a process with a ProcessStartInfo object then a Process object is created:
VB Code:
'Create the ProcessStartInfo.
Dim psi1 As New ProcessStartInfo
'Set the properties.
psi1.FileName = filePath
psi1.Arguments = arguments
'Start the process and create the Process object.
Dim proc1 As Process = Process.Start(psi1)
VB Code:
'Create the ProcessStartInfo with the desired parameters.
Dim psi2 As New ProcessStartInfo(filePath, arguments)
'Start the process and create the Process object.
Dim proc2 As Process = Process.Start(psi2)
VB Code:
'Create the new process object.
Dim proc3 As New Process
'Set the properties.
proc3.StartInfo.FileName = filePath
proc3.StartInfo.Arguments = arguments
'Start the process.
proc3.Start()
-
Aug 8th, 2006, 06:53 AM
#4
Thread Starter
Fanatic Member
Re: [2005] Running a program with parameters
Oh thanks you two. I used gigemboy's version, but I think i'll use jmcilhinney's simplified version instead. Thanks for the help!
-
Aug 14th, 2007, 05:42 PM
#5
Lively Member
Re: [RESOLVED] [2005] Running a program with parameters
jmcilhinney's
in all the forum there is an example on how to process.start and passing comandlines to an X application but how would it be to do it with the cmd.exe? How can I pass comandlines to the cmd window? Already tried many things but can't get the comandlines to be writen on the cmd window.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|