Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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?

like image 856
athom Avatar asked Dec 18 '12 22:12

athom


People also ask

Is there a way to see what processes are running on a remote computer Powershell?

To get all running processes on the remote computer, you need to use – ComputerNameparameter in Get-process cmdlet, WMI class Win32_Process or using the Get-CimInstance cmdlet.

How do I view a process in Powershell?

The Get-Process cmdlet gets the processes on a local or remote computer. Without parameters, this cmdlet gets all of the processes on the local computer. You can also specify a particular process by process name or process ID (PID) or pass a process object through the pipeline to this cmdlet.

How do I see CPU usage on Windows remote?

Click Operation on the top, and then choose Task Manager to open it directly. Step 7. In the Task Manager, go to the Performance tab, and then you can check the CPU and memory usage of the remote computer intuitively.


1 Answers

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;
    }
}
like image 154
athom Avatar answered Sep 20 '22 23:09

athom