1

我正在尝试编写一个解锁位锁定驱动器的批处理脚本。首先,我正在尝试检查驱动器是否已锁定。到目前为止,我有:

:: 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 命令中似乎不起作用。其他一切似乎都正常。我怎样才能做到这一点?

4

1 回答 1

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
)
于 2013-01-31T05:01:18.480 回答