8

これまでにこれを達成するために2つの方法を試しました。

最初の方法で を使用System.Diagnosticsしましたが、NotSupportedExceptionで「機能はリモート マシンではサポートされていません」というメッセージが表示されMainModuleます。

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

2番目の方法で、使用し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());
}

リモートマシンで実行中のプロセスの説明を取得するためのより良い方法を知っている人はいますか?

4

1 に答える 1

5

まあ、私はこれを行う方法を持っていると思います。これは私の目的には十分に機能します。私は基本的に からファイル パス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;
    }
}
于 2013-01-07T19:59:14.767 に答える