5

I'm using Microsoft Visual Studio to make a simple remote task manager for experience purposes.

I want to use Process.GetProcesses(string); but there is an access denied exception that won't allow me to get the remote computer process. In fact it is normal because we should authenticate using a user name and password, but how?

kapa
  • 77,694
  • 21
  • 158
  • 175
Peyman
  • 3,059
  • 1
  • 33
  • 68

3 Answers3

2

You may try to use 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());
}

For further details on Win32_Process class see MSDN.

hth

Pilgerstorfer Franz
  • 8,303
  • 3
  • 41
  • 54
1

EDIT: Just read your post again, the steps described in my post only apply in a domain, I assume you work inside a workgroup. I'm sorry.

I recently ran into a similar issue when running Visual Studio as Administrator on Windows 7. It seems like permissions on remote machines and network shares are dropped (even in a domain!) if you elevate your program to run as local administrator, which will be the case if you run a program out of VS when VS is run as admin. This even happens if you have domain wide admin accounts.

Try the following:

  • Build the solution
  • Run it manually with your account which has hopefully privileges on the remote computer from windows explorer, without elevation

If this helps, you could stop running VS as administrator. It worked out for me.

Emiswelt
  • 3,909
  • 1
  • 38
  • 56
0

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

sternr
  • 6,216
  • 9
  • 39
  • 63