2017-03-28 15 views
0

これまでのところ、私は(hresult from IMbnInterfaceManager::GetInterfaces when no MBN device existsを参照)MbnInterfaceManagerが動作を取得するために苦労しているので、代わりに私は(もWin32_PerfFormattedData_Tcpip_NetworkInterface documentationを参照)C#で、このWMIクエリを実行するのVisual Studio 2015内から問題なく使用してアプリケーションをビルドしてデバッグ:Windows 7、8.1、および10の帯域幅はどのように決定できますか?

string query = "SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface"; 
ManagementObjectSearcher moSearch = new ManagementObjectSearcher(query); 
ManagementObjectCollection moCollection = moSearch.Get(); 

しかし、私は、Windows 8.1にアプリケーションを展開したとき、私はこのエラーにクエリが実行されるたびに受け取る:

System.Management.ManagementException: Invalid query 
    at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) 
    at System.Management.ManagementObjectCollection.ManagementObjectEnumerator.MoveNext() 

は、誰もがこの問題を解決する方法上の任意の提案を持っていますか?このようなクエリを使用できるようにアプリケーションを配備するにはどうすればよいですか?

UPDATE:

Windows 7またはWindows 8.1のいずれかにVisual Studio 2015内から(より大きなWPFアプリケーションの一部として)私は上記のコードをビルドして実行できることに注意してください、と私は展開することができますしてくださいClickOnceを使用してWindows 7に正常に実行される同じアプリケーション。何らかの理由で、私はこのアプリケーションをWindows 8.1にClickOnceを使って配備すると、Invalid queryというメッセージが表示されます。

答えて

0

私は、System.Managementリファレンスが "ローカルコピー"に設定されていることを確認していますが、今はそのテストを行うことができません。誰かより良いアイデアがあれば、私に教えてください。

UPDATE:

それは、Windows 7またはWindows 10

で使用されているのと同じ方法でWindows 8.1にSystem.Management.dllを使用することはできません私が見つけたのことWindows 8.1の開発者ライセンスを取得するか、Windows 10にコンピュータを「開発者モード」に設定してWindows.Networking.Connectivity名前空間を使用できるようにするために、Windows 8.1とWindows 8の電話で私の質問で述べた操作と同様の操作を実行します。

  string connectionProfileInfo = string.Empty; 
      ConnectionProfile InternetConnectionProfile = NetworkInformation.GetInternetConnectionProfile(); 

      if (InternetConnectionProfile == null) 
      { 
       rootPage.NotifyUser("Not connected to Internet\n", NotifyType.StatusMessage); 
      } 
      else 
      { 
       connectionProfileInfo = GetConnectionProfile(InternetConnectionProfile); 
       OutputText.Text = connectionProfileInfo; 
       rootPage.NotifyUser("Success", NotifyType.StatusMessage); 
      } 

      // Which calls this function, that allows you to determine how strong the signal is and the associated bandwidth 
      string GetConnectionProfile(ConnectionProfile connectionProfile) 
      { 
       // ... 
        if (connectionProfile.GetSignalBars().HasValue) 
        { 
         connectionProfileInfo += "====================\n"; 
         connectionProfileInfo += "Signal Bars: " + connectionProfile.GetSignalBars() + "\n"; 
        } 
       // ... 
      } 

名前空間を参照できるように、プロジェクトがWindow 8.1 PCLまたはWindows 8.1アプリケーションであることを確認する必要があります。詳細について

参照してください。https://code.msdn.microsoft.com/windowsapps/network-information-sample-63aaa201

UPDATE 2:

private int GetMaxBandwidth() 
    { 
     int maxBandwidth = 0; 
     NetworkInterface[] networkIntrInterfaces = NetworkInterface.GetAllNetworkInterfaces(); 

     foreach (var networkInterface in networkIntrInterfaces) 
     { 
      IPv4InterfaceStatistics interfaceStats = networkInterface.GetIPv4Statistics(); 
      int bytesSentSpeed = (int)(interfaceStats.BytesSent); 
      int bytesReceivedSpeed = (int)(interfaceStats.BytesReceived); 

      if (bytesSentSpeed + bytesReceivedSpeed > maxBandwidth) 
      { 
       maxBandwidth = bytesSentSpeed + bytesReceivedSpeed; 
      } 
     } 
    } 

のWindows 7、8.1及び10の帯域幅を得ることができるように、私はこのコードを使用して終了

関連する問題