如何获得一个正在运行的进程在远程计算机上的说明? [英] How to get the description of a running process on a remote machine?

查看:290
本文介绍了如何获得一个正在运行的进程在远程计算机上的说明?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了两种方式,到目前为止,完成这一任务。



第一种方式,我用 System.Diagnostics程序,但我得到一个引发NotSupportedException 的功能不支持远程计算机关于 MainModule

 的foreach(在Process.GetProcesses过程runningProcess(server.Name))
{
Console.WriteLine(runningProcess。 MainModule.FileVersionInfo.FileDescription);
}



第二种方式,我试图用 System.Management ,但它似乎说明的ManagementObject 为她一样的<$的C $ C>名称。

 字符串范围= @\\+服务器。名+ @\root\cimv2 
查询字符串=选择的Win32_Process *;
ManagementObjectSearcher搜索=新ManagementObjectSearcher(范围,查询);
ManagementObjectCollection集合= searcher.Get();

的foreach(在收集的ManagementObject OBJ)
{
Console.WriteLine(OBJ [名称]的ToString());
Console.WriteLine(OBJ [说明]的ToString());
}



有没有人知道发生一个更好的方式去获得的说明在远程计算机上正在运行的进程?


解决方案

嗯,我想我已经得到了这样的方法,将工作不够好我的目的。我基本上得到的文件路径关闭的ManagementObject 并得到从实际文件中的描述。



<$ P $的p> ConnectionOptions连接=新ConnectionOptions();
connection.Username =用户名;
connection.Password =密码;
connection.Authority =ntlmdomain:DOMAIN;

管理范围范围=新的管理范围(@\\+服务器名+ @\root\cimv2连接);
scope.Connect();

的ObjectQuery查询=新的ObjectQuery(选择Win32_Process的*);
ManagementObjectSearcher搜索=新ManagementObjectSearcher(范围,查询);
ManagementObjectCollection集合= searcher.Get();

的foreach(在收集的ManagementObject OBJ)
{
如果(OBJ [ExecutablePath]!= NULL)
{
串processPath = OBJ [ ExecutablePath]的ToString()更换(:,$)。
processPath = @\\+服务器名+ @\+ processPath;

FileVersionInfo信息= FileVersionInfo.GetVersionInfo(processPath);
串processDesc = info.FileDescription;
}
}


I have tried two ways to accomplish this so far.

The first way, I used System.Diagnostics, but I get a NotSupportedException of "Feature is not supported for remote machines" on the MainModule.

foreach (Process runningProcess in Process.GetProcesses(server.Name))
{
    Console.WriteLine(runningProcess.MainModule.FileVersionInfo.FileDescription);
}

The second way, I attempted using System.Management but it seems that the Description of the ManagementObject is the she same as the Name.

string scope = @"\\" + server.Name + @"\root\cimv2";
string query = "select * from Win32_Process";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection collection = searcher.Get();

foreach (ManagementObject obj in collection)
{
    Console.WriteLine(obj["Name"].ToString());
    Console.WriteLine(obj["Description"].ToString());
}

Would anyone happen to know of a better way to go about getting the descriptions of a running process on a remote machine?

解决方案

Well I think I've got a method of doing this that will work well enough for my purposes. I'm basically getting the file path off of the ManagementObject and getting the description from the actual file.

ConnectionOptions connection = new ConnectionOptions();
connection.Username = "username";
connection.Password = "password";
connection.Authority = "ntlmdomain:DOMAIN";

ManagementScope scope = new ManagementScope(@"\\" + serverName + @"\root\cimv2", connection);
scope.Connect();

ObjectQuery query = new ObjectQuery("select * from Win32_Process");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection collection = searcher.Get();

foreach (ManagementObject obj in collection)
{
    if (obj["ExecutablePath"] != null)
    {
        string processPath = obj["ExecutablePath"].ToString().Replace(":", "$");
        processPath = @"\\" + serverName + @"\" + processPath;

        FileVersionInfo info = FileVersionInfo.GetVersionInfo(processPath);
        string processDesc = info.FileDescription;
    }
}

这篇关于如何获得一个正在运行的进程在远程计算机上的说明?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆