0

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;
    }
Rich Shealer
  • 3,362
  • 1
  • 34
  • 59
  • Did you try testing this code in Virtual Machines? I have the similar problem where I am using c#.net to query WMI to list the printers installed on the machine. If I am running the code locally it works fine but as soon as it comes to virtual machine, ( i am using VB6 -> C# COM Interop) the list is empty. Is client using Virtual Machines? – atp9 Jun 23 '15 at 07:24
  • @atp_09 This is real hardware. Unfortunately it is in a locked down area that I can't get remote access to for testing. They have USB ports disabled via group policy. That is why I'm thinking it is a policy issue for this. – Rich Shealer Jun 23 '15 at 13:08
  • 1
    then how about testing the query via Wbemtest tool? Can you give it a try? – atp9 Jun 23 '15 at 14:16
  • @atp_09 Thanks. I didn't know about that tool. It may be a few days until they can get to the machine for testing. – Rich Shealer Jun 23 '15 at 15:08
  • Yes it is the tool using which you can actually test detail by providing your WQL and executing it. It is bit handy tool. Give it a try and let us know if something doesn't work. But yes, you may want to experiment that tool. – atp9 Jun 23 '15 at 17:14

1 Answers1

0

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.

Rich Shealer
  • 3,362
  • 1
  • 34
  • 59