Restart another application. C # ,. net

I want to restart some process. Lets call it someApp.exe. How can I restart this process? This is not my application. This is some kind of external program.

+6
source share
2 answers

What do you want to do:

  • Kill the process
  • Run it again

There are several ways to get a Process instance in C #. Suppose you know the name of a process:

var process = Process.GetProcessesByName("notepad++")[0]; 

Then you can do:

 process.Kill(); 

But to start it again, you need to know the path to the process, so before killing it, save the path to the executable file:

 var path = process.MainModule.FileName; 

And then you can do:

 Process.Start(path); 


You should check if GetProcessesByName elements before the first element, but I just wanted to focus on the important thing here.
+8
source

Source: https://habr.com/ru/post/887750/


All Articles