c# – 进程是否在远程计算机上运行?

我有三台远程连接的远程PC.我正在尝试编写一个简单的 Windows应用程序,该应用程序将在单个窗口中显示特定进程是否在任一计算机上运行,​​例如

Server1:Chrome未运行

Server2:Chrome正在运行

Server3:Chrome正在运行

我使用了WMI和C#.到目前为止,我有这么多:

Connectionoptions connectoptions = new Connectionoptions();

            connectoptions.Username = @"domain\username";
            connectoptions.Password = "password";

            //IP Address of the remote machine
            string ipAddress = "192.168.0.217";
            ManagementScope scope = new ManagementScope(@"\\" + ipAddress + @"\root\cimv2");
            scope.Options = connectoptions;
            //Define the WMI query to be executed on the remote machine
            SelectQuery query = new SelectQuery("select * from Win32_Process");

            using (ManagementObjectSearcher searcher = new
                        ManagementObjectSearcher(scope,query))
            {

                ManagementObjectCollection collection = searcher.Get();
                foreach (ManagementObject process in collection)
                {
                    // dwarfs stole the code!! :'(                        
                }
            }

我认为这一切都设置正确,但如果我在foreach循环中的MessageBox.Show(process.ToString()),我会得到一大堆带有以下文本的消息框:

\\username\root\cimv2:W32_Process.Handle="XXX"

我有点卡住了.有什么办法可以将XXX翻译成流程名称吗?或者,如何实际获取进程的名称,以便我可以使用if语句来检查它是否是“chrome”进程?

或者……我的实施是否过度杀伤?有没有更简单的方法来实现这一目标?

非常感谢!

解决方法

在你的foreach中,试试这个:
Console.WriteLine(process["Name"]);

相关文章

在要实现单例模式的类当中添加如下代码:实例化的时候:frmC...
1、如果制作圆角窗体,窗体先继承DOTNETBAR的:public parti...
根据网上资料,自己很粗略的实现了一个winform搜索提示,但是...
近期在做DSOFramer这个控件,打算自己弄一个自定义控件来封装...
今天玩了一把WMI,查询了一下电脑的硬件信息,感觉很多代码都...
最近在研究WinWordControl这个控件,因为上级要求在系统里,...