Bitlocker的检查状态为null

时间:2019-08-27 02:52:23

标签: c# windows-api-code-pack bitlocker

我创建了一个代码块,用于检查机器中的位锁是否已启用,遵循以下主题:Detect BitLocker programmatically from c# without admin 我几乎在所有机器上都运行良好,但是从现在开始有机器返回null值:

IShellProperty prop = ShellObject.FromParsingName(rootDrive).Properties.GetProperty("System.Volume.BitLockerProtection");
int? bitLockerProtectionStatus = (prop as ShellProperty<int?>).Value; // bitLockerProtectionStatus return null

这台机器已经安装了bitlocker。我已经使用命令“ manage-bde -status C:”检查了状态,并返回状态“完全加密”。

仅提及以上主题,如果此属性的值为1、3或5,则在驱动器上启用了BitLocker。其他任何值均视为关闭。 该值如何返回null,我在哪里可以在计算机中检查此值(“ System.Volume.BitLockerProtection”)?

1 个答案:

答案 0 :(得分:0)

我的用于检测Bitlocker驱动器的代码:

if (!new DriveInfo(DriveName).IsReady)
{
    Process p = Process.Start(new ProcessStartInfo()
    {
        FileName = "cmd.exe",
        Arguments = " /C " + DriveName,
        Verb = "runas",
        UseShellExecute = false,
        RedirectStandardOutput = true,
        RedirectStandardError = true
    });
    string error = p.StandardError.ReadToEnd();
    string console = p.StandardOutput.ReadToEnd();
    bool IsBitLockerDrive = (error + console).Contains("BitLocker");//pw protected drive
}
相关问题