在没有管理员的情况下从 c# 以编程方式检测 BitLocker
Detect BitLocker programmatically from c# without admin
从各种线程中,我拼凑了如何以编程方式检查 BitLocker,如下所示:
private void TestBitLockerMenuItem_Click(object sender, RoutedEventArgs e) {
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());
foreach (var item in objectSearcher.GetInstances()) {
MessageBox.Show(item["DeviceID"].ToString()+" "+item["ProtectionStatus"].ToString());
}
}
但它只有在进程具有管理员权限时才有效。
任何老 Windows 用户都可以转到资源管理器,右键单击驱动器,然后查看它是否启用了 BitLocker,这似乎很奇怪,但程序似乎无法完成此操作。有谁知道这样做的方法吗?
Windows 通过使用 Win32 API 中的 Windows Property System 在 shell 中显示此内容以检查未记录的 shell 属性 System.Volume.BitLockerProtection
。您的程序还可以在不提升的情况下检查此 属性。
如果此 属性 的值为 1、3 或 5,则驱动器上启用了 BitLocker。任何其他值都被视为关闭。
在寻找此问题的解决方案期间,我在 HKEY_CLASSES_ROOT\Drive\shell\manage-bde\AppliesTo
中找到了对此 shell 属性 的引用。最终,这一发现使我找到了这个解决方案。
Windows 属性 系统是低级 API,但您可以使用 Windows API Code Pack.
中可用的包装器
套餐
Install-Package WindowsAPICodePack
正在使用
using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
代码
IShellProperty prop = ShellObject.FromParsingName("C:").Properties.GetProperty("System.Volume.BitLockerProtection");
int? bitLockerProtectionStatus = (prop as ShellProperty<int?>).Value;
if (bitLockerProtectionStatus.HasValue && (bitLockerProtectionStatus == 1 || bitLockerProtectionStatus == 3 || bitLockerProtectionStatus == 5))
Console.WriteLine("ON");
else
Console.WriteLine("OFF");
从各种线程中,我拼凑了如何以编程方式检查 BitLocker,如下所示:
private void TestBitLockerMenuItem_Click(object sender, RoutedEventArgs e) {
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());
foreach (var item in objectSearcher.GetInstances()) {
MessageBox.Show(item["DeviceID"].ToString()+" "+item["ProtectionStatus"].ToString());
}
}
但它只有在进程具有管理员权限时才有效。
任何老 Windows 用户都可以转到资源管理器,右键单击驱动器,然后查看它是否启用了 BitLocker,这似乎很奇怪,但程序似乎无法完成此操作。有谁知道这样做的方法吗?
Windows 通过使用 Win32 API 中的 Windows Property System 在 shell 中显示此内容以检查未记录的 shell 属性 System.Volume.BitLockerProtection
。您的程序还可以在不提升的情况下检查此 属性。
如果此 属性 的值为 1、3 或 5,则驱动器上启用了 BitLocker。任何其他值都被视为关闭。
在寻找此问题的解决方案期间,我在 HKEY_CLASSES_ROOT\Drive\shell\manage-bde\AppliesTo
中找到了对此 shell 属性 的引用。最终,这一发现使我找到了这个解决方案。
Windows 属性 系统是低级 API,但您可以使用 Windows API Code Pack.
中可用的包装器套餐
Install-Package WindowsAPICodePack
正在使用
using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
代码
IShellProperty prop = ShellObject.FromParsingName("C:").Properties.GetProperty("System.Volume.BitLockerProtection");
int? bitLockerProtectionStatus = (prop as ShellProperty<int?>).Value;
if (bitLockerProtectionStatus.HasValue && (bitLockerProtectionStatus == 1 || bitLockerProtectionStatus == 3 || bitLockerProtectionStatus == 5))
Console.WriteLine("ON");
else
Console.WriteLine("OFF");