Reputation: 29703
I want to restart some process. Lets call it someApp.exe. How can I restart that process? It's not my application. It's some external program.
Upvotes: 6
Views: 7061
Reputation: 29863
What you want to do is:
There are some ways of obtaining a Process instance in C#. 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.
Upvotes: 12
Reputation: 5312
You can use the Process.Start.
http://msdn.microsoft.com/en-us/library/53ezey2s.aspx#Y1400
Upvotes: 0