Search code examples
c#.netwmi

the query Win32_NetworkAdapterConfiguration return HRESULT: 0x80070422


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;
        }

Solution

  • 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