How to get a description of a running process on a remote machine?

I have tried two ways to do this so far.

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

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

Secondly, I tried to use System.Management , but it seems that Description for ManagementObject is the same as 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()); } 

Does anyone possibly find out about a more efficient way to get descriptions of a running process on a remote machine?

+8
c # process wmi remote-access
source share
1 answer

Well, I think I have a way to do this, which will work well for my purposes. I basically get the file path from ManagementObject and get 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; } } 
+4
source share

All Articles