为什么 new ManagementObject(@"root\WMI", "BcdStore", null) 抛出异常? [英] Why new ManagementObject(@"root\WMI", "BcdStore", null) throws exception?

查看:26
本文介绍了为什么 new ManagementObject(@"root\WMI", "BcdStore", null) 抛出异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 WMI Code Creator,我尝试调用 root\WMI\BcdStore.EnumerateObjects().但是我在第一行代码中得到一个异常:

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");

// ... 

例外是:

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.

怎么了?

推荐答案

ManagementObject 您正在使用的构造函数需要一个 WMI 路径作为参数,而您只传递类名,所以您必须使用这样的东西.

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

这篇关于为什么 new ManagementObject(@"root\WMI", "BcdStore", null) 抛出异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆