查询 Win32_NetworkAdapterConfiguration return HRESULT: 0x80070422
the query Win32_NetworkAdapterConfiguration return HRESULT: 0x80070422
我有下面的代码从 machine 获取物理 mac 地址,它在大多数情况下工作正常但在某些情况下我收到错误
像这样(原来的错误信息不是英文,所以我试着自己翻译):
the service couldn't be started because it's disable or doesn't have
an associated active devices (exception HRESULT: 0x80070422)
无法启动或禁用的服务是什么?我该如何解决这个问题?
这是我使用的代码:
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;
}
看起来 Windows Management Instrumentation service
是 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
我有下面的代码从 machine 获取物理 mac 地址,它在大多数情况下工作正常但在某些情况下我收到错误 像这样(原来的错误信息不是英文,所以我试着自己翻译):
the service couldn't be started because it's disable or doesn't have an associated active devices (exception HRESULT: 0x80070422)
无法启动或禁用的服务是什么?我该如何解决这个问题?
这是我使用的代码:
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;
}
看起来 Windows Management Instrumentation service
是 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