0

因此,我正在编写一个脚本,该脚本应该能够解密 bitlocker 加密驱动器,显示百分比和转换状态,每隔几秒刷新这 2 个。问题是当它刷新时,它认为任务已经完成并进入下一步。

由于环境的性质,该脚本需要是 cmd 。

提前感谢您的洞察力和/或协助!

这是让我悲伤的代码部分:

:statusloop
cls
set done=
set done=Conversion Status:    Fully Decrypted
for /f "tokens=*" %%i in ('manage-bde -status C: ^| findstr /C:"Conversion"') do ^set status1=%%i
for /f "tokens=*" %%i in ('manage-bde -status C: ^| findstr /C:"Percent"') do ^set STATUS=%%i
echo %status1%
echo %status%
ping 127.0.0.1>nul
if "%status1%" == "%done%" goto decryptedreboot 
    else goto statusloop

对于那些需要一切的人,这里是所有代码:

@echo OFF

goto check_Permissions

:check_Permissions
    echo Administrative permissions required. Detecting permissions...

    net session >nul 2>&1
    if %errorLevel% == 0 (
        echo Success: Administrative permissions confirmed.
        echo Standby for launch...
        ping 127.0.0.1>nul
        goto checker
    ) else (
        color C
        echo Failure: Current permissions inadequate.
        echo Please run as Admin and try again.
        ping 127.0.0.1>nul
        exit
    )

:checker
setlocal
for /f "tokens=4-5 delims=. " %%i in ('ver') do set VERSION=%%i.%%j
if "%version%" == "6.3" goto nope
if "%version%" == "6.2" goto nope
if "%version%" == "6.1" goto nope
if "%version%" == "6.0" goto nope
if "%version%" == "10.0" goto begin
rem etc etc
endlocal
goto begin

::Recovery Key - Paste or type in the recovery key between the quotes.
set rpin="" 

::No Comment
:begin

color A
cls
color 7
echo -----------------------------------------------
echo                Bitlocker Toolkit
echo -----------------------------------------------
echo.
echo How may I assist you today?
echo. 
echo 1) Get Recovery Key ID and 48 number recovery pin
echo 2) Change Bitlocker Pin
echo 3) Unlock the drive
echo 4) Decrypt this machine
echo 5) Oops! Wrong file, I need to exit! 
echo.
echo.
echo.
set ask=
set /p ask=I pick number:
if '%ask%'=='1' goto keys
if '%ask%'=='2' goto changepin
if '%ask%'=='3' goto unlock
if '%ask%'=='4' goto decrypt
if '%ask%'=='5' goto goodbye


:keys

cls
manage-bde -protectors C: -get

set ask=
set/p ask=Export to desktop? (Y/N):
if '%ask%'=='Y' goto export
if '%ask%'=='y' goto export
if '%ask%'=='N' goto begin
if '%ask%'=='n' goto begin

:export
cls
manage-bde -protectors C: -get>%userprofile%\Desktop\Bltiocker_recovery_key.txt
echo Exporting to Bitlocker_recovery_key.txt on Desktop\Bltiocker_recovery_key
ping 127.0.0.1>nul
goto begin

:changepin

manage-bde -changepin C:

pause

goto begin

:unlock
cls
IF "%rpin%"=="" set /p rpin=Please enter the recovery key including dashes:
manage-bde -unlock C: -recoverypassword %rpin%
pause
goto begin

:decrypt
cls
echo Last chance to turn back! Are you sure you want to decrypt
echo this machine?
echo.
echo.
set ask=
set/p ask=Are you sure? (Y/N):
if '%ask%'=='Y' goto begindecryptreboot
if '%ask%'=='y' goto begindecryptreboot
if '%ask%'=='N' goto begin
if '%ask%'=='n' goto begin

:begindecryptreboot
cls
IF "%rpin%"=="" set /p rpin=Please enter the recovery key including dashes:
manage-bde -unlock C: -recoverypassword %rpin%
ping 127.0.0.1>nul
manage-bde -off C:
cls
goto statusloop

:statusloop
cls
set done=
set done=Conversion Status:    Fully Decrypted
for /f "tokens=*" %%i in ('manage-bde -status C: ^| findstr /C:"Conversion"') do ^set status1=%%i
for /f "tokens=*" %%i in ('manage-bde -status C: ^| findstr /C:"Percent"') do ^set STATUS=%%i
echo %status1%
echo %status%
ping 127.0.0.1>nul
if "%status1%" == "%done%" goto decryptedreboot 
    else goto statusloop

:decryptedreboot
cls
echo Decryption complete. This PC will reboot in 5 minutes...
shutdown /f /r /t 300
echo Press any key to abort the reboot.
pause>nul
shutdown /a
cls
echo The shutdown has been aborted, returning to main menu...
timeout /t 5>nul
goto begin

::XP & 7 detection
:Nope
cls
color c
echo ***FATAL ERROR***
echo.
echo.
echo THIS SOLUTION IS DESIGNED ONLY FOR WINDOWS 10 COMPUTERS. YOU SHALL NOT PASS!
pause >nul
exit

::Goodbye, cruel world!
:goodbye
cls
color 3
echo Thank you for using the Bitlocker Toolkit.
echo.
echo.
echo.
echo So long and thanks for all the fish!
echo.
echo.
echo.
timeout /t 05 
exit /b
4

1 回答 1

0

在你的行中

  else goto statusloop

删除else. 您不需要它,并且由于您的if语法错误,它只会生成错误消息并继续下一行代码,即您的关闭代码。

正确if的语法是(如果你真的想保留else):

if "%status1%" == "%done%" ( 
  goto decryptedreboot 
) else ( 
  goto statusloop
)

注意:) else (必须在同一条物理线上(并且空格很重要)

于 2018-03-21T17:54:50.573 回答