swtool

 

public void Kill(string filePath)
        {
            var wmiQueryString = "SELECT ProcessId, ExecutablePath, CommandLine FROM Win32_Process";
            using (var searcher = new ManagementObjectSearcher(wmiQueryString))
            using (var results = searcher.Get())
            {
                var query = from p in Process.GetProcesses()
                            join mo in results.Cast<ManagementObject>()
                            on p.Id equals (int)(uint)mo["ProcessId"]
                            select new
                            {
                                Process = p,
                                Path = (string)mo["ExecutablePath"],
                                CommandLine = (string)mo["CommandLine"],
                            };

                foreach (var item in query)
                {
                    if (filePath == item.Path)
                    {
                        item.Process.Kill();

                        item.Process.WaitForExit();
                    }
                }
            }
        }

 

分类:

技术点:

相关文章:

  • 2021-08-06
  • 2021-12-28
  • 2021-11-10
  • 2021-09-04
  • 2021-12-03
  • 2021-12-15
  • 2021-11-06
猜你喜欢
  • 2021-12-13
  • 2021-09-20
  • 2021-11-18
  • 2021-06-14
  • 2021-11-20
  • 2021-11-15
  • 2018-07-26
相关资源
相似解决方案