Running EXE with parameters

橙三吉。 提交于 2020-01-17 22:31:56

问题


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.


回答1:


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();



回答2:


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



回答3:


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


来源:https://stackoverflow.com/questions/59596463/c-sharp-run-exe-with-custom-parameters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!