the query Win32_NetworkAdapterConfiguration return HRESULT: 0x80070422

0

I have below code to get the physical mac address from a machine, it works fine in most but in some I get an error like that (the orginal error message isn't English, so I'm trying to translate it myself):

the service couldn't be started because it's disable or doesn't have an associated active devices (exception HRESULT: 0x80070422)

What's that service that couldn't be started or is disable? how do I fix this?

Here's the code I'm using:

public string GetMACAddress()
        {
            ManagementObjectSearcher objMOS = new ManagementObjectSearcher("Select * FROM Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection objMOC = objMOS.Get();
            string macAddress = String.Empty;
            foreach (ManagementObject objMO in objMOC)
            {
                object tempMacAddrObj = objMO["MacAddress"];

                if (tempMacAddrObj == null) //Skip objects without a MACAddress
                {
                    continue;
                }
                if (macAddress == String.Empty) // only return MAC Address from first card that has a MAC Address
                {
                    macAddress = tempMacAddrObj.ToString();
                }
                objMO.Dispose();
            }
            return macAddress;
        }
c#
.net
wmi
asked on Stack Overflow Apr 22, 2016 by Jack

1 Answer

1

It looks like Windows Management Instrumentation service is down/disabled.

Click Start

Click Run

Type services.msc and press . This will open the Services window

Scroll down to Windows Management Instrumentation service.

Right click on the service

Verify that the service is started and set to Automatic.

Click OK

answered on Stack Overflow Apr 23, 2016 by Amit Shakya

User contributions licensed under CC BY-SA 3.0