WMI GetPropertyQualifierValue“未找到”
我的问题非常简单,但显然没有人遇到过类似的错误。我正在编写一个程序来检查 WMI 类的属性是否可写,即该属性的“Write”限定符是否为 true。我的代码如下所示:
ManagementObjectSearcher mos = new ManagementObjectSearcher("root\\\CIMV2", "SELECT * FROM " + "Win32_Processor"); <br />
ManagementObjectCollection moc= mos.Get(); <br />
ManagementClass manClass = new ManagementClass("Win32_Processor"); <br />
bool isWriteable = false;
isWriteable (bool)manClass.GetPropertyQualifierValue("Description", "Write"); <br />
// I've also tried to call it on a ManagementObject instance of ManagementObjectCollection, doesn't work either way
但是,每次调用它时,它都会返回“未找到”异常,无论我使用哪个属性或限定符名称(我尝试过的所有属性或限定符名称都是从 MSDN 中提取的 - 它们应该是有效的)。
同样,在尝试获取类的限定符时,GetQualifierValue
也不起作用。
有人有什么想法吗?
My question is really simple, but apparently nobody's experienced a similar error. I'm writing a program to check if a WMI Class's property is writeable, that is, if the "Write" qualifier is true for that property. My code looks like this:
ManagementObjectSearcher mos = new ManagementObjectSearcher("root\\\CIMV2", "SELECT * FROM " + "Win32_Processor"); <br />
ManagementObjectCollection moc= mos.Get(); <br />
ManagementClass manClass = new ManagementClass("Win32_Processor"); <br />
bool isWriteable = false;
isWriteable (bool)manClass.GetPropertyQualifierValue("Description", "Write"); <br />
// I've also tried to call it on a ManagementObject instance of ManagementObjectCollection, doesn't work either way
Every time it's called, however, it returns a "Not found" exception, regardless of which property or qualifier name I use (all of the one's I've tried I've pulled from MSDN — they should be valid).
Similarly, GetQualifierValue
does not work, either, when trying to get the qualifiers of the class.
Anyone have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查类属性是否可写的正确方法是检查“write”限定符是否存在。以下是一些示例代码:
使用下面的代码,您将看到 Description 属性仅具有 CIMTYPE、Description 和 read 限定符。
The proper way to check if a Class’ property is writeable is to check for the existence of the “write” qualifier. The following is some sample code:
Using the code below, you will see that the Description property only has the CIMTYPE, Description, and read qualifiers.