Hi. I'm trying to read some WMI properties to collect hardware data of a remote machine. Problem is, it runs w/o error but tells me my local machine hardware instead. I'm sure I just made some silly mistake, but I don't see it:
ConnectionOptions co = new ConnectionOptions();
co.Username = null;
ManagementScope ms = new ManagementScope("\\\\remotepcname", co);
ObjectQuery q = new ObjectQuery("select * from Win32_PointingDevice");
using (ManagementObjectSearcher os = new ManagementObjectSearcher(ms, q)) {
using (ManagementObjectCollection moc = os.Get()) {
foreach (ManagementObject o in moc) {
MessageBox.Show("Mouse: " + o["Name"].ToString());
}
}
}
I tried changing the co.Username = null to:
co.Username = "domain\\user";
co.Password = "pwd";
but that threw an exception that it cannot be done on local connections.
??
Loading
Sam HobbsPosted Jul 6, 2011, 3:09 PM
See the sample there? Do you see the sample has "\\\\FullComputerName\\root\\cimv2"? Also, do you see the line saying "scope.Connect();"?
Also, look at the "IsConnected" property.
Also, use try/catch to ensure you get error messages.