29

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.

Sai Avinash
  • 4,623
  • 17
  • 55
  • 94
Privesh
  • 477
  • 2
  • 10
  • 19

3 Answers3

65

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();
amhed
  • 3,621
  • 2
  • 30
  • 56
Stephan Bauer
  • 8,611
  • 5
  • 37
  • 57
19
System.Diagnostics.Process.Start("PATH to exe", "Command Line Arguments");
undone
  • 7,787
  • 4
  • 43
  • 69
9
ProcessStartInfo startInfo = new ProcessStartInfo(string.Concat(cPath, "\\", "HHTCtrlp.exe"));
startInfo.Arguments =cParams;
startInfo.UseShellExecute = false; 
System.Diagnostics.Process.Start(startInfo);
Zied R.
  • 4,909
  • 2
  • 36
  • 64