How to get permissions to use System.Diagnostics.Process.GetProcess (string)?

I use Microsoft Visual Studio to create a simple remote task manager for expert purposes.

I want to use Process.GetProcesses(string);, but there is an exception that excludes access, which will not allow me to get the process of a remote computer. This is actually normal, because we must authenticate using the username and password , but how ?

+5
source share
3 answers

You can try using WMI for this purpose.

/// using System.Management;  
// don't forget! in VS you may have to add a new reference to this DLL
ConnectionOptions op = new ConnectionOptions();
op.Username = "REMOTE_USER";
op.Password = "REMOTE_PASSWORD";

ManagementScope sc = new ManagementScope(@"\\REMOTE_COMPUTER_NAME\root\cimv2", op);

ObjectQuery query = new ObjectQuery("Select * from Win32_Process");

ManagementObjectSearcher searcher = new ManagementObjectSearcher(sc, query);
ManagementObjectCollection result = searcher.Get();

foreach (ManagementObject obj in result)
{
     if (obj["Caption"] != null) Console.Write(obj["Caption"].ToString() + "\t");
     if (obj["CommandLine"] != null) Console.WriteLine(obj["CommandLine"].ToString());
}

Win32_Process . MSDN.

HTH

+2

: , , , , , . .

Visual Studio Windows 7. , ( !), , , VS, VS admin. , .

:

  • , , Windows Explorer, .

, VS . .

+1

I'm sure you need a boost to do this, or at least use a stronger user impersonation

0
source

All Articles