1

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

ManagementClass objectSearcher;
            List<string> BitLocker = new List<string>();

            objectSearcher = new ManagementClass("Win32_EncryptableVolume");
            foreach (var item in objectSearcher.GetInstances())
            {
                try
                {
                 BitLocker.Add(item["DeviceID"].ToString());
                 BitLocker.Add(item["ProtectionStatus"].ToString());

                }
                catch
                {
                    BitLocker.Add("Error, could not retrieve data. \n");
                }

            }

图片1

4

1 回答 1

3

我相信您需要先设置路径和范围,例如:

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());
于 2013-09-17T18:25:03.153 回答