为什么 WMI 通过搜索而不是直接工作? [英] Why does WMI work through a search but not directly?

查看:28
本文介绍了为什么 WMI 通过搜索而不是直接工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这两个中的第一个锁定 BitLocked 驱动器.第二个的 InvokeMethod 抛出:'无效的对象路径'.为什么?他们似乎是等价的.

The first of these 2 locks a BitLocked drive. The 2nd's InvokeMethod throws: 'Invalid object path'. Why? They seem equivalent.

//Using a search:
ManagementObjectSearcher searcher = new ManagementObjectSearcher("root\\CIMV2\\Security\\MicrosoftVolumeEncryption", "SELECT * FROM Win32_EncryptableVolume WHERE DriveLetter = 'E:'");
foreach (ManagementObject classInstance1 in searcher.Get())
    classInstance1.InvokeMethod("Lock", new object[] { true }); 

//Direct:
ManagementObject classInstance2 = new ManagementObject("root\\CIMV2\\Security\\MicrosoftVolumeEncryption", "Win32_EncryptableVolume.DriveLetter='E:'", null);
classInstance2.InvokeMethod("Lock", new object[] { 0 });//throws: 'Invalid object path'.

推荐答案

我只是假设正确答案与其他人提到的相似但不完全相同.

I'll just assume that the correct answer is similar to what the others have mentioned but not exactly.

课程页面提到DeviceID 具有以下属性:

限定符:关键

我假设,由于缺乏实际文档,通过他们的 Key 搜索某物会返回该事物本身.通过其他方式搜索时,会返回满足该条件的对象列表.即使列表只包含 1 个条目 - 它也不是对象本身,而是一个列表.

I assume, for lack of actual documentation, that searching for something by their Key returns the thing itself. While searching by something else returns a list of objects that satisfy that condition. Even if the list contains only 1 entry - it's not the object itself but rather a list.

但如果有人能提供一些文档,那就太好了.

But if someone could supply some documentation, that would be nice.

这篇关于为什么 WMI 通过搜索而不是直接工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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