Kill some processes by .exe file name

后端 未结 6 914
情深已故
情深已故 2020-11-27 02:45

How can I kill some active processes by searching for their .exe filenames in C# .NET or C++?

6条回答
  •  北海茫月
    2020-11-27 03:03

    public void EndTask(string taskname)
    {
          string processName = taskname.Replace(".exe", "");
    
          foreach (Process process in Process.GetProcessesByName(processName))
          {
              process.Kill();
          }
    }
    
    //EndTask("notepad");
    

    Summary: no matter if the name contains .exe, the process will end. You don't need to "leave off .exe from process name", It works 100%.

提交回复
热议问题