无需admin即可从c#以编程方式检测BitLocker

从各种线程我拼凑如何以编程方式检查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属性系统在shell中显示此内容,以检查未记录的shell属性System.Volume.BitLockerProtection 。 您的程序也可以在没有高程的情况下检查此属性。

如果此属性的值为1,3或5,则在驱动器上启用BitLocker。 任何其他值都被视为关闭。

在我搜索此问题的解决方案期间,我在HKEY_CLASSES_ROOT\Drive\shell\manage-bde\AppliesTo找到了对此shell属性的引用。 最终,这一发现引导我找到这个解决方案。

Windows Property System是一个低级API,但您可以使用Windows API代码包中提供的包装器。

 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).Value; if (bitLockerProtectionStatus.HasValue && (bitLockerProtectionStatus == 1 || bitLockerProtectionStatus == 3 || bitLockerProtectionStatus == 5)) Console.WriteLine("ON"); else Console.WriteLine("OFF"); 
Interesting Posts