2016-01-28 26 views
5

我已经在Windows 7中工作的下面的代码:HRESULT时没有MBN设备存在

  MbnInterfaceManager mbnInfMgr = new MbnInterfaceManager(); 
      IMbnInterfaceManager mbnInfMgrInterface = mbnInfMgr as IMbnInterfaceManager; 

      if (mbnInfMgrInterface != null) 
      { 
       IMbnInterface[] mobileInterfaces = mbnInfMgrInterface.GetInterfaces() as IMbnInterface[]; 
      } 

当MBN设备存在,但是当MBN设备不存在我得到的没有问题在调用GetInterfaces()后出现异常:

{System.Runtime.InteropServices.COMException(0x80070490):找不到元素。 (从HRESULT异常:0x80070490) 在MbnApi.IMbnInterfaceManager.GetInterfaces() 在foo.Program.configureConnection()在FOO}

问题 有什么应该做检查前的MBN接口调用GetInterfaces?我可以简单地捕捉到这个异常,但我找不到任何说这个异常与没有接口相同的文档。

我在statckoverflow上发现的最接近的东西是 struggling with mobile broadband api windows 7 and windows 8 with C#, not sure what to install 这意味着Windows 7的行为可能与Windows 8.1不同。

+0

我注意到这种情况发生在某些蜂窝调制解调器硬件上,如果某些设备管理器中的“设备”被禁用。 –

回答

0

我得到了相同的Element not found异常试图使用GetSignalStrength()和MbnInterfaceManager我反而发现你可以使用WMI获得很多有用的信息。请看这里使用SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface答案:

struggling with mobile broadband api windows 7 and windows 8 with C#, not sure what to install

UPDATE:

请注意,我发现你不能在Windows 8.1的网络信息以同样的方式,你在Windows 7做。请参阅How can I install an application that requires WMI capabilities on Windows 8.1 to determine available bandwidth?https://code.msdn.microsoft.com/windowsapps/network-information-sample-63aaa201