Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Win32_EncryptableVolume在C中获取bitlocker状态#_C#_Wmi_Status - Fatal编程技术网

C# Win32_EncryptableVolume在C中获取bitlocker状态#

C# Win32_EncryptableVolume在C中获取bitlocker状态#,c#,wmi,status,C#,Wmi,Status,在c#中,我使用以下代码获取BitLocker的状态。 当我运行脚本时,脚本显示:管理异常未处理。 有什么想法吗 ManagementClass对象搜索器; List BitLocker=新列表(); objectSearcher=新的管理类(“Win32_EncryptableVolume”); foreach(objectSearcher.GetInstances()中的var项) { 尝试 { 添加(项[“设备ID”].ToString()); 添加(项[“ProtectionStatus

在c#中,我使用以下代码获取BitLocker的状态。 当我运行脚本时,脚本显示:管理异常未处理。 有什么想法吗

ManagementClass对象搜索器;
List BitLocker=新列表();
objectSearcher=新的管理类(“Win32_EncryptableVolume”);
foreach(objectSearcher.GetInstances()中的var项)
{
尝试
{
添加(项[“设备ID”].ToString());
添加(项[“ProtectionStatus”].ToString());
}
抓住
{
BitLocker.Add(“错误,无法检索数据。\n”);
}
}


我认为您需要首先设置路径和范围,例如:

var path = new ManagementPath(@"\ROOT\CIMV2\Security\MicrosoftVolumeEncryption") { ClassName = "Win32_EncryptableVolume" };
var scope = new ManagementScope(path);
path.Server = Environment.MachineName;
var objectSearcher = new ManagementClass(scope, path, new ObjectGetOptions());

就这样吧!
var path = new ManagementPath(@"\ROOT\CIMV2\Security\MicrosoftVolumeEncryption") { ClassName = "Win32_EncryptableVolume" };
var scope = new ManagementScope(path);
path.Server = Environment.MachineName;
var objectSearcher = new ManagementClass(scope, path, new ObjectGetOptions());