Why can't local Windows 7 Pro machine read its own WMI values?

93 views Asked by At

As part of a larger .Net 4.0 program I have a piece that queries the WMI for a list of network adapters and from that creates a list<> of physical adapters with MAC addresses.

It works on the machines I've tried it on, but when sent to the client, the list is empty. If they run IPCONFIG /ALL at a command prompt the MACs are listed.

My first thought is that there is a group policy in place preventing the enumeration, but everything I've found so far points to group policies that affects remote access through the firewall.

I've tried it locally as both a standard user and administration user, both provide the same list.

The empty query does not generate an exception.

I could ask them to go to the machines and check individual permissions, but since this seems to be a group issue that seems to be the wrong direction. What am I missing?

  public static List<WmiNetworkInterfaceItem> QueryphysicalNetworkInterfaces()
    {
      ManagementObjectSearcher searcher =
          new ManagementObjectSearcher("root\\CIMV2",
          "SELECT * FROM Win32_NetworkAdapter");

      List<WmiNetworkInterfaceItem> result = new List<WmiNetworkInterfaceItem>();

      foreach (ManagementObject queryObj in searcher.Get()) {
        if (queryObj["PhysicalAdapter"].Equals(true)) {
          if (queryObj["AdapterTypeId"] != null) {
            if (queryObj["AdapterTypeId"].ToString().Equals("0")) {
              WmiNetworkInterfaceItem wmiNetworkInterfaceItem = new WmiNetworkInterfaceItem();
              wmiNetworkInterfaceItem.Name = ManagementObjectPropertyString(queryObj["Name"]);
              wmiNetworkInterfaceItem.MacAddress = ManagementObjectPropertyString(queryObj["MACAddress"]);
              wmiNetworkInterfaceItem.PhysicalAdapter = queryObj["PhysicalAdapter"].Equals(true);
              wmiNetworkInterfaceItem.AdapterType = ManagementObjectPropertyString(queryObj["AdapterType"]);
              wmiNetworkInterfaceItem.AdapterTypeId = -1;
              int.TryParse(ManagementObjectPropertyString(queryObj["AdapterTypeId"]), out wmiNetworkInterfaceItem.AdapterTypeId);
              wmiNetworkInterfaceItem.Description = ManagementObjectPropertyString(queryObj["Description"]);
              wmiNetworkInterfaceItem.PermanentAddress = ManagementObjectPropertyString(queryObj["PermanentAddress"]);
              result.Add(wmiNetworkInterfaceItem);
            }
          }
        }
      }
      return result;
    }
1

There are 1 answers

0
Rich Shealer On BEST ANSWER

Using the WBEMTest utility included with Windows as suggested by user atp_09 in comments, I was able to have the customer query his machine. Using this query exactly one adapter was returned in both standard and administrative user accounts indicating there was nothing in the machine preventing this from working.

SELECT * FROM Win32_NetworkAdapter where PhysicalAdapter = true 

Upon further review there was an error in how I later dealt with the list with a single response.