c# - MSFT_NetAdapter 类无效

标签 c# networking windows-8 wmi windows-server-2012

我正在尝试在 Windows 8 中使用新的 WMI 类 MSFT_NetAdapter 而不是 Win32_NetworkAdapter

using System;
using System.Management;

namespace TestAdapters
{
    class Program
    {
        static void Main(string[] args)
        {
            string query = "SELECT * From MSFT_NetAdapter";
            ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
            ManagementObjectCollection adaptersCollection = searcher.Get();
            foreach (ManagementObject adapterWmiObject in adaptersCollection) //System.Management.ManagementException
            {
                //...
            }
            Console.WriteLine("end.");
            Console.ReadKey();
        }
    }
}

我在 foreach 语句中得到一个 System.Management.ManagementException 消息:无效类

不知道是什么意思。我在 Windows 8.1 x64 下编译和运行代码,所以这个类必须工作。

如何使用MSFT_NetAdapter

最佳答案

此类不在 root\Cimv2 命名空间中。

root\StandardCimv2 命名空间中查找它。

查看以下 Powershell:

PS C:\Scripts> Get-WmiObject MSFT_NetAdapter
Get-WmiObject : Invalid class "MSFT_NetAdapter"
At line:1 char:1
+ Get-WmiObject MSFT_NetAdapter
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidType: (:) [Get-WmiObject], ManagementException
    + FullyQualifiedErrorId : GetWMIManagementException,Microsoft.PowerShell.Commands.GetWmiObjectCommand


PS C:\Scripts> Get-WmiObject MSFT_NetAdapter -Namespace root\StandardCimv2
SUCCESS

关于c# - MSFT_NetAdapter 类无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21236095/

相关文章:

c - 我如何计算以下 TCP/IP 协议(protocol)的 CRC 校验和

windows-8 - 如何禁用 Windows 8 (WinRT) 锁定屏幕

c# - 从返回 403 forbidden 的网站解析

c# - 托管线程会影响 C dll 中的全局变量吗?

C 从套接字读取直到换行

c++ - 接口(interface)名称(eth0 等)的等效 inet_addr C/C++、Linux

python - 安装Scrapy时出现错误 "Could not find ' openssl.exe'

c# - 在这种情况下可以覆盖 ToString() 方法吗

c# - Youtube 数据 API : Retrieving multiple Video entries by IDs in a single request

c# - 使用 RSACryptoServiceProvider 从 XML 导入 RSA 公钥将属性 PublicOnly 设置为 false