[英]Restart other application. C#, .net
I want to restart some process. 我想重启一些过程。 Lets call it someApp.exe.
让我们称之为someApp.exe。 How can I restart that process?
如何重新启动该过程? It's not my application.
这不是我的申请。 It's some external program.
这是一些外部程序。
What you want to do is: 你想要做的是:
There are some ways of obtaining a Process instance in C#. 有一些方法可以在C#中获取Process实例。 Let's suppose you know the name of the process:
假设您知道进程的名称:
var process = Process.GetProcessesByName("notepad++")[0];
Then you can do: 然后你可以这样做:
process.Kill();
But to start it again, you need to know the path of the process, so before killing it, save the path of the executable: 但要重新启动它,您需要知道进程的路径,因此在杀死它之前,请保存可执行文件的路径:
var path = process.MainModule.FileName;
And then you can do: 然后你可以这样做:
Process.Start(path);
GetProcessesByName
returns elements before taking the first element, but I just wanted to focus on the important thing here.
GetProcessesByName
返回元素,但我只想关注重要的事情。
You can use the Process.Start. 您可以使用Process.Start。
http://msdn.microsoft.com/en-us/library/53ezey2s.aspx#Y1400 http://msdn.microsoft.com/en-us/library/53ezey2s.aspx#Y1400
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.