batch-file - manage-bde protectionaserrorlevel 不起作用
问题描述
嘿嘿,我正在编写一个批处理文件来定期检查是否启用了 bitlocker。但是,我意识到,在我可以使用任何多汁的自动化部分之前,我只是通过运行 manage-bde -status c: -p (作为管理员)得到一个错误。有人可以提供一个正确使用 manage-bde -status c: -p 的例子吗?我正在使用 64 位 Windows 10 机器。这是我的脚本和输出。谢谢!
@ECHO OFF
manage-bde -status c: -p
ECHO %ERRORLEVEL%
PAUSE
EXIT
结果是我在运行 manage-bde -status c: 时通常会得到的结果,并添加了一条错误消息:
Volume C: [Windows]
[OS Volume]
Size: 471.56 GB
BitLocker Version: None
Conversion Status: Fully Decrypted
Percentage Encrypted: 0.0%
Encryption Method: None
Protection Status: Protection Off
Lock Status: Unlocked
Identification Field: None
Key Protectors: None Found
ERROR: While performing the operation, a component unexpectedly returned FALSE.
-1
Press any key to continue . . .
解决方案
以下示例使用了 manage-bde 命令的替代方法,您可能会发现该方法很有用。
该变量%ProtectionStatus%
应包含0
、1
或的值2
。
以后的行6
应该输出消息来解释这些整数的含义。
您可以随时根据您的要求更改该部分。
@Echo Off & SetLocal EnableExtensions
Set "ProtectionStatus=" & For /F Tokens^=* %%G In ('WMIC.exe
/NameSpace:\\ROOT\CIMV2\Security\MicrosoftVolumeEncryption Path
Win32_EncryptableVolume Where "DriveLetter='%SystemDrive%'" Call
GetProtectionStatus 2^>NUL ^| find.exe "ProtectionStatus "')Do Set /A %%G 2>NUL
If Defined ProtectionStatus (If %ProtectionStatus% Equ 0 (Echo The volume is^
not encrypted, partially encrypted, or the encryption key for the volume is^
available in the clear on the hard disk.)Else If %ProtectionStatus% Equ 1 (
Echo The volume is fully encrypted and the encryption key for the volume is not^
available in the clear on the hard disk.)Else Echo The volume is either^
locked, or its protection status cannot be determined.)Else Echo An unknown^
error occurred.
Pause
请注意,这也需要“以管理员身份运行”
推荐阅读
- angular - 如何从 Angular 的库中导出模型?
- haskell - Haskell:大量读写时IOArray太慢
- msys2 - 使用 MSYS2 安装旧的 Python 3.6
- python - 如何从 Python 中的文本文件计算中位数?
- javascript - 在本机反应中重置组件的状态?
- angular - 在 Angular 中等待带有 if 条件的 Observable 响应
- sql - UPDATE 查询卡在执行 regexp_replace 函数
- python - 在 SQLAlchemy 中,如何在使用乐观锁更新后获取受影响的行?
- cs-cart - 我们如何在安装后使 cs cart api 工作?
- xamarin - 如何在 Xamarin MAC 平台中更改选取器背景颜色