Privesh
Privesh

Reputation: 657

Running EXE with parameters

I need help in trying to execute an executable from my C# application.
Suppose the path is cPath, the EXE is HHTCtrlp.exe and the parameter that has to be passed is cParams.

How would I go about this?

The reason why the path is a variable is that there are 3 different EXE files to run and the path will change depending on which one will run, same with the parameter string.

Any help would be greatly appreciated.

Upvotes: 36

Views: 149199

Answers (3)

Stephan Bauer
Stephan Bauer

Reputation: 9249

To start the process with parameters, you can use following code:

string filename = Path.Combine(cPath,"HHTCtrlp.exe");
var proc = System.Diagnostics.Process.Start(filename, cParams);

To kill/exit the program again, you can use following code:

proc.CloseMainWindow(); 
proc.Close();

Upvotes: 77

Zied R.
Zied R.

Reputation: 4964

ProcessStartInfo startInfo = new ProcessStartInfo(string.Concat(cPath, "\\", "HHTCtrlp.exe"));
startInfo.Arguments =cParams;
startInfo.UseShellExecute = false; 
System.Diagnostics.Process.Start(startInfo);

Upvotes: 10

undone
undone

Reputation: 7888

System.Diagnostics.Process.Start("PATH to exe", "Command Line Arguments");

Upvotes: 23

Related Questions