programmatically kill a process in vista/windows 7 in C#

后端 未结 2 1866
忘掉有多难
忘掉有多难 2020-12-17 20:40

I want to kill a process programmatically in vista/windows 7 (I\'m not sure if there\'s significant problems in the implementation of the UAC between the two to make a diffe

2条回答
  •  不思量自难忘°
    2020-12-17 21:31

    I'll add the code for Simon Buchan's suggestion. It makes sense and should work as well, assuming your windows form is what launched the process in the first place.

    Here's where you create the process. Notice the variable myProc. That's your handle on it:

    System.Diagnostics.Process myProc = new System.Diagnostics.Process();
    myProc.EnableRaisingEvents=false;
    myProc.StartInfo.FileName="PATH_TO_EXE";
    myProc.Start();
    

    Later, just kill it with:

    myProc.Kill();
    

提交回复
热议问题