[英]How to get the description of a running process on a remote machine?
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
. 第一种方法,我使用了
System.Diagnostics
,但是在MainModule
上收到NotSupportedException
的“远程计算机不支持功能”。
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
. 第二种方法,我尝试使用
System.Management
但似乎ManagementObject
的Description
与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. 我基本上是从
ManagementObject
获取文件路径,并从实际文件中获取描述。
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.