Why new ManagementObject(@“root\WMI”, “BcdStore”,

2019-09-11 07:52发布

Using WMI Code Creator, I'm trying to issue a call to root\WMI\BcdStore.EnumerateObjects(). However I get an exception on the first line of code:

var classInstance = new ManagementObject(
    @"root\WMI", "BcdStore", null); // <== exception!!!

// Obtain in-parameters for the method
var inParams = classInstance.GetMethodParameters("EnumerateObjects");

// ... 

The exception is:

A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in System.Management.dll

Additional information: Specified argument was out of the range of valid values.

What's wrong?

标签: c# wmi
1条回答
Melony?
2楼-- · 2019-09-11 08:23

The version of the ManagementObject constructor which you are using is expecting a WMI Path as parameter, and you are only passing the class name, so you must use some thing like this.

var classInstance = ManagementObject(@"root\WMI", "BcdStore.FilePath=''", null);

Note : The system store is denoted by an empty string ("").

查看更多
登录 后发表回答