AutoCAD.Net/C#.Net QQ群:193522571 32位进程无法访问64位进程模块,解决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();
                    }
                }
            }
        }
原文地址:https://www.cnblogs.com/swtool/p/11289135.html