I'm trying to collect process information from remote machines using System.Management.
I'm impersonating an admin on the remote machine using something along these lines, but the following code throws an exception: "Access Denied".
ConnectionOptions options = new ConnectionOptions();
options.Impersonation = System.Management.ImpersonationLevel.Impersonate;
ManagementScope scope = new ManagementScope(@"\\" + machine + @"\root\cimv2", options);
scope.Connect();
ObjectQuery query = new ObjectQuery("Select * from Win32_Process where ProcessId = "
+ procID.ToString());
ManagementObjectSearcher mos = new ManagementObjectSearcher(scope, query);
string cmdLn = "";
foreach (ManagementObject mo in mos.Get())
{
cmdLn = (string)mo.GetPropertyValue("CommandLine");
}
However, if I supply the username and password to options
, everything works fine.
I've verified that this code is executing as the impersonated context (which has sufficient permissions on the remote machine), so I'm not sure why it isn't working without the username/password passed.
Is it possible to authenticate successfully WITHOUT explicitly passing the user's credentials?