Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running EXE with parameters

Tags:

c#

executable

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.

like image 838
Privesh Avatar asked Aug 10 '11 09:08

Privesh


People also ask

How do I add parameters to an exe?

To add launch parameters to the shortcut, click or tap inside the Target text field, and type all the arguments you want to add to it, at the end of the line. Each of the additional launch parameters must be preceded by a blank space and a hyphen.

How do I run an EXE file from a PowerShell parameter?

You can run exe files in powershell different ways. For instance if you want to run unrar.exe and extract a . rar file you can simply write in powershell this: $extract_path = "C:\Program Files\Containing folder"; $rar_to_extract = "C:\Path_to_arch\file.

Can you run .exe from CMD?

Type "start [filename.exe]" into Command Prompt, replacing "filename" with the name of your selected file. Replace "[filename.exe]" with your program's name. This allows you to run your program from the file path.


2 Answers

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(); 
like image 100
Stephan Bauer Avatar answered Sep 19 '22 15:09

Stephan Bauer


System.Diagnostics.Process.Start("PATH to exe", "Command Line Arguments"); 
like image 40
undone Avatar answered Sep 19 '22 15:09

undone