ath*_*hom 8 c# wmi process remote-access
到目前为止,我已尝试过两种方法来完成此任务.
第一种方式,我用过System.Diagnostics,但我得到了NotSupportedException"远程机器不支持功能" MainModule.
foreach (Process runningProcess in Process.GetProcesses(server.Name))
{
Console.WriteLine(runningProcess.MainModule.FileVersionInfo.FileDescription);
}
Run Code Online (Sandbox Code Playgroud)
第二种方式,我尝试使用System.Management,但它似乎是Description的ManagementObject是的,她一样的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());
}
Run Code Online (Sandbox Code Playgroud)
有人会碰巧知道在远程机器上获取正在运行的进程的描述的更好方法吗?
好吧,我想我已经有了一种方法,可以很好地满足我的目的.我基本上是从文件路径中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;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4333 次 |
| 最近记录: |