1
Answer

Reading WMI properties remotely?

Ken

Ken

13y
1.2k
1
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.

??

Answers (1)