Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在wmi c中检索Win32#U ComputerSystem实例?_C#_.net_Wmi - Fatal编程技术网

C# 如何在wmi c中检索Win32#U ComputerSystem实例?

C# 如何在wmi c中检索Win32#U ComputerSystem实例?,c#,.net,wmi,C#,.net,Wmi,大家好:) 在该类中,Win32_SystemDevices类中的链接 在property GroupComponent中,它返回Win32_ComputerSystem类的一个实例,但我在System.Manager中找不到这样的类 我认为这个属性返回内存中的实例,但是如何捕获这个实例呢 我尝试了一些代码,但我到此为止 static void Main(string[] args) { ManagementClass diskClass = new M

大家好:)

在该类中,Win32_SystemDevices类中的链接

在property GroupComponent中,它返回Win32_ComputerSystem类的一个实例,但我在System.Manager中找不到这样的类

我认为这个属性返回内存中的实例,但是如何捕获这个实例呢

我尝试了一些代码,但我到此为止

static void Main(string[] args)
    {
        ManagementClass diskClass =
         new ManagementClass("Win32_SystemDevices");

        ManagementClass jo = new ManagementClass("Win32_ComputerSystem");


        var disks =
            diskClass.GetInstances();

        foreach (var e in disks)
        {


        }



        Console.ReadKey();
    }

有人能帮我吗,谢谢:)

虽然Win32_ComputerSystem类在技术上不是一个单例类,但它在我见过的所有系统中都被视为一个单例类(我很好奇,有人看到过这种情况,请在下面评论。因此,本着单例类的精神,它只有一个实例

在Win32_SystemDevices类中,属性GroupComponent只是对Win32_ComputerSystem中唯一实例的引用,您可以使用以下代码执行此操作

ManagementObject ComputerSystem = new ManagementObject($@"ROOT\CIMV2:Win32_ComputerSystem.Name='{Environment.MachineName}'");

希望这能有所帮助。

您能澄清一下吗?您希望达到的最终结果是什么。Win32\u ComputerSystem是一个有效的WMI。@PaulG,从这个链接中,Win32\u ComputerSystem类中有许多属性,我想从通过Win32\u SystemDevices类的属性返回的实例中获取这些属性,我的意思是我想要cat从Win32_SystemDevices.GroupComponent属性中调用Win32_ComputerSystem实例,是否理解我broo:)??