quick question - launching external application

uberamd

Member
Joined
Jan 22, 2007
Messages
9
Programming Experience
Beginner
Hey everyone:

I am trying to make a click event that will launch an external application. However, the application has launch parameters that need to be set in order for the application to launch.

The code in question:

VB.NET:
System.Diagnostics.Process.Start("C:\App\Run.exe -- -s Station  subscriptionFeatures=1 gameFeatures=255")
Now, the -- -s etc. parameters are required to make the program run, and that is exactly what the shortcut looks like for the application (without the System.Diagnostics.Process.Start("")), so is there a way for me to add those parameters to the exe to make it launch properly?

Edit: I noticed that the app tries to launch but it cannot find files. Reason: much like a shortcut the program needs a "Start In" directory to be set, and Start In would be C:\App. Is there a way to say: Start In C:\App, launch C:\App\Run.exe -- -s Station etc...?

Thanks!
 
Use the Process.Start method that accepts a System.Diagnostics.ProcessStartInfo object as a parameter. The ProcessStartInfo class has a WorkingDirectory property:
VB.NET:
Dim startInfo As New ProcessStartInfo("C:\App\Run.exe")
startInfo.WorkingDirectory = "C:\App"
startInfo.Arguments = "-- -s Station  subscriptionFeatures=1 gameFeatures=255"
Process.Start(startInfo)
 
Thanks! I had been searching but nothing I attempted tried. I had settled with this hacked together solution, but thank you for a proper one:
VB.NET:
        Dim FileToDelete As String
        FileToDelete = "launch.bat"
        If System.IO.File.Exists(FileToDelete) = True Then 
            System.IO.File.Delete(FileToDelete) 
        End If 
        Dim fs As New FileStream("launch.bat", FileMode.Create, FileAccess.Write)
        Dim s As New StreamWriter(fs) 
        s.BaseStream.Seek(0, SeekOrigin.End) 
        s.WriteLine("cd C:\StarWarsGalaxiesEmu")
        s.WriteLine("C:\StarWarsGalaxiesEmu\SWGEmu.exe -- -s Station  subscriptionFeatures=1 gameFeatures=255")
        Dim myProcess As Process = New Process() 
        myProcess.StartInfo.FileName = "launch.bat"
        myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Minimized 
        myProcess.Start()
 
Back
Top