Querying remote hosts not working?

Mar 15, 2011 at 10:38 PM

 

Trying to query a remote host is not working for me.  In testing, I'm using the following:

using (WmiContext context = new WmiContext(@"\\A_Remote_Machine"))
{
	context.ManagementScope.Options.Impersonation = ImpersonationLevel.Impersonate;
	context.Log = Console.Out;
	QueryProcessors(context);
}
private static void QueryProcessors(WmiContext context)
{
	var query = from processor in context.Source<Win32_Processor>()
			select processor;

	foreach (Win32_Processor processor in query)
	{
		Console.WriteLine(String.Format("DeviceID: {0}", processor.DeviceID));
		Console.WriteLine(String.Format("Speed: {0} mhz", processor.CurrentClockSpeed));
		Console.WriteLine(String.Format("Usage: {0}%", processor.LoadPercentage));
	}
}

I'm getting the local processor, not the processor from A_Remote_Machine.  Any ideas?

 

May 25, 2011 at 4:20 PM
aderuwe wrote:

 Trying to query a remote host is not working for me.  In testing, I'm using the following:

using (WmiContext context = new WmiContext(@"\\A_Remote_Machine"))
{
context.ManagementScope.Options.Impersonation = ImpersonationLevel.Impersonate;
context.Log = Console.Out;
QueryProcessors(context);
}

I found that when you specify the WmiContext constructor with a suffix of the namespace you are connecting to everything works. So:

using (WmiContext context = new WmiContext(@\\A_Remote_Machine\root\cimv2))

Is the ticket!

 

 

Sep 21, 2011 at 10:07 PM

Thank you DBaines!