AutoCAD.Net/C#.Net QQ group: 19,352,257,132 64-bit process can not access the process module, to solve the problem of ineffective methods getprocesses 32

 

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();
                    }
                }
            }
        }

 

Guess you like

Origin www.cnblogs.com/swtool/p/11289135.html