Why new ManagementObject(@“root\WMI”, “BcdStore”, null) throws exception?

狂风中的少年 提交于 2020-01-17 04:49:17

问题


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?


回答1:


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 ("").



来源:https://stackoverflow.com/questions/28967075/why-new-managementobjectroot-wmi-bcdstore-null-throws-exception

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!