从各种线程我拼凑如何以编程方式检查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());
}
}
Run Code Online (Sandbox Code Playgroud)
但它仅在进程具有管理员权限时才有效.
看起来奇怪的是,任何旧的Windows用户都可以转到资源管理器,右键单击某个驱动器,然后查看它是否已启用BitLocker,但程序似乎无法完成此操作.有谁知道这样做的方法?
Windows通过使用Win32 API中的Windows Property System来检查未记录的shell属性,从而在shell中显示此信息System.Volume.BitLockerProtection.您的程序也可以在没有高程的情况下检查此属性.
如果此属性的值为1,3或5,则在驱动器上启用BitLocker.任何其他值都被视为关闭.
在我搜索此问题的解决方案期间,我发现了对此shell属性的引用HKEY_CLASSES_ROOT\Drive\shell\manage-bde\AppliesTo.最终,这一发现引导我找到这个解决方案.
Windows Property System是一个低级API,但您可以使用Windows API代码包中提供的包装器.
Install-Package WindowsAPICodePack
Run Code Online (Sandbox Code Playgroud)
using Microsoft.WindowsAPICodePack.Shell;
using Microsoft.WindowsAPICodePack.Shell.PropertySystem;
Run Code Online (Sandbox Code Playgroud)
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");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3466 次 |
| 最近记录: |