我正在尝试编写一个解锁一个锁定驱动器的批处理脚本。首先,我正在尝试检查驱动器是否已锁定。到目前为止,我已经:
:: Check if the drive is already unlocked
set unlockstatus=0
FOR /F "tokens=*" %%i IN ('manage-bde -status %inp%') DO (
echo %%i | find /c "Unlocked" | set /p found=
if %found%==1 set unlockstatus=1
)
if %unlockstatus%==1 (
echo This drive is already unlocked.
goto input
)
%inp%是一个驱动器号,后跟一个冒号。
出于某种原因,这种直接行为不起作用。看起来由于某种原因,输入到第二行的set命令的管道输入不起作用。其他一切似乎都运转正常。我怎么能做到这一点?
答案 0 :(得分:0)
使用另一个for循环来解析find命令的结果。
:: Check if the drive is already unlocked
set "unlockstatus=0"
FOR /F "tokens=*" %%A IN ('manage-bde -status %inp%') DO (
FOR /F "tokens=*" %%B in ('echo %%A ^| find /c "Unlocked"') DO (
if "%%B"=="1" set "unlockstatus=1"
)
)
if "%unlockstatus%"=="1" (
echo This drive is already unlocked.
goto input
)