Completing the process using C # dll. I wanted to create a dll, which would complete the processes, but it did not work out.

public static string notepad() { Process process = Process.Start("notepad.exe"); process.Kill(); } 

What's wrong?

  • Can you tell us in more detail what does not work out and what message crashes. - Murad Nov.
  • Apparently nothing flies: the process is created and immediately chopped - what do you expect from this miracle code? To make sure you add a “slip” between the start and the keel. - wind
  • Error 1 "DLLKill.Class1.notepad ()": not all branches of the code return the value C: \ Users \ SuperUser \ Documents \ Visual Studio 2012 \ Projects \ DLLKill \ DLLKill \ Class1.cs 13 30 DLLKill - Vlad Andreev
  • one
    return string.Empty; - Murad
  • Most likely, you are trying to complete the process before it is fully spawned ( Process.Start returns too quickly, without waiting for all internal structures to initialize). - ߊߚߤߘ

2 answers 2

 string killNameProcess = "notepad"; Process[] processes = Process.GetProcessesByName(killNameProcess); processes.First().Kill(); 
  • Thank you, but I need not by name but by process - Vlad Andreev Nov.
  • What does the process mean? (by the name you get the process, and then kill it). - Murad Nov.
  • You can go through all the processes and see the path to the executable file if the name is not enough. - Modus
 Process[] proc = Process.GetProcesses(); foreach (Process process in proc) if (process.ProcessName == "notepad") process.Kill();