how run exe file in c# [duplicate]

风格不统一 提交于 2019-12-10 23:47:38

问题


I made an application that requires functionality to run iisreset.exe. My application is on deploy in server. so iisreset should be server not client machine. I use process.start() but it reset iis of client machine. what code i should modify.


回答1:


Use the Process class to execute a process.

How To: Execute command line in C#, get STD OUT results

 // Start the child process.
 Process p = new Process();
 // Redirect the output stream of the child process.
 p.StartInfo.UseShellExecute = false;
 p.StartInfo.RedirectStandardOutput = true;
 p.StartInfo.FileName = "YOURBATCHFILE.bat";
 p.Start();
 // Do not wait for the child process to exit before
 // reading to the end of its redirected stream.
 // p.WaitForExit();
 // Read the output stream first and then wait.
 string output = p.StandardOutput.ReadToEnd();
 p.WaitForExit();



回答2:


Use Process.Start()

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx

Tie into the OnExited event to get when it exits.

Further, consider the impact iisreset has on the system as a whole. If others run sites on that same server, they may not be too happy with your software.



来源:https://stackoverflow.com/questions/6658386/how-run-exe-file-in-c-sharp

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