Shelling a file with options

mekilla

Member
Joined
Jun 5, 2003
Messages
18
Hi, I am wondering if it is possible to start a executable with options in vb.net. Basically I can run a game via start>run, and then add the option +restart 1.

So I am running: E:\program files\games\game.exe +restart 1

Everything works fine but I cannot seem to find a way to do it in an application. I have tried to Shell it, use the System.Diagnostics.Process.Start method, and also just create a new Process and start it. Most ways give a file not found exception, some do not. Basically when it works the introduction is skipped. I think the main problem is that I have no idea what this is called, Arguments? EnvironmentVariables? Any ideas or thoughts would be greatly appreciated!
 
Code:
System.Diagnostics.Process.Start("E:\Program Files\Games\Game.exe", "+restart 1")
:) the Process.Start function has a separate parameter for command line parameters (arguments).
 
Thanks for the reply! I actually tried that and it is not working either. In fact just System.Diagnostics.Process.Start("E:\Program Files\Games\Game.exe") does not open it. The computer sounds like it is doing something for a split second but in the end, does nothing.

I checked the task manager and it does pop up the game then the game closes which is the same thing that happens when an incorrect arg is sent in. This game seems to dislike this and all shell methods.

Is there a way to use the run feature of windows?
 
I just figured it out! I only needed to specify a working directory and now everything works fine!
 
Sorry for the late reply!

Dim pr As New ProcessStartInfo()
pr.WorkingDirectory = "WORKING DIRECTORY" Working directory here
pr.FileName = "FILE PATH"
pr.Arguments = "ARGUMENTS"
pr.UseShellExecute = True
Process.Start(pr)
 
Working directory is the "default directory" in the programs eyes; if the program attempts to access file using relative path (i.e. "images\img.jpg" instead of "c:\game\moo\images\img.jpg"), that is the directory it will look in.
 
Back
Top