我想要完成的是批处理文件将执行某人通常单独输入的命令(这需要时间),所以我想将其变成一个带有检查点和其他内容的无缝流程......
我可以让一些事情起作用,但不是全部,它会跳过不应该的地方,也不会跳过应该的地方。
我使用了不同的方法,例如 Errorlevel 和变量,但这使情况变得更糟,我在这里提交的方法是我拥有的所有版本中“最实用”的:
@ECHO OFF
TITLE YEY-Computer-Checker
START /b /wait cmd.exe /c chkdsk /f/r /y
ECHO The program will continue dont worry! This will only be showed once!
timeout /t 5 nobreak
cls
START /b /wait cmd.exe /c sfc /scannow
timeout /t 5 /nobreak
cls
START /b cmd.exe /c DISM /Online /Cleanup-Image /CheckHealth
timeout /t 5 /nobreak
cls
START /b /wait cmd.exe /c DISM /Online /Cleanup-Image /ScanHealth
timeout /t 5 /nobreak
cls
IF NOT ERRORLEVEL 1 START /b /wait cmd.exe /c DISM /Online /Cleanup-Image /RestoreHealth
timeout /t 5 /nobreak
cls
:end ECHO The YEY-Computer-Checker has finished! Your System seems to be alright! The Programm will close in 5s or press Enter to close immediately.
:Error ECHO The Programm has encountered an Error! And will close automatically in 5s.
timeout /t 5
EXIT
这是更新版本!可以这么说,版本 1.1(95% 功能正常,第一个回显被忽略,缺少伪加载栏)
@ECHO OFF
TITLE YEY-Computer-Checker
chkdsk /f/r /y
ECHO The program will continue dont worry! This will only be showed once!
timeout /t 10 nobreak >nul
cls
sfc /scannow
timeout /t 10 /nobreak >nul
cls
DISM /Online /Cleanup-Image /CheckHealth
timeout /t 10 /nobreak >nul
cls
DISM /Online /Cleanup-Image /ScanHealth
cls
IF NOT ERRORLEVEL 0 DISM /Online /Cleanup-Image /RestoreHealth
timeout /t 10 /nobreak >nul
cls
ECHO Do you wish to do a [Q]uick Scan a [F]ull Scan or [N]either of the two?
ECHO\
ECHO A Quick Scan will take approx. 10 mins.
ECHO\
ECHO A Full Scan will take longer, approx. 60 mins.
:again
set /p choice=
IF %choice%==Q (
"C:\Program Files\Windows Defender\MpCmdRun.exe" -Scan -ScanType 1
)
IF %choice%==F (
"C:\Program Files\Windows Defender\MpCmdRun.exe" -Scan -ScanType 2
)
IF %choice%==N ECHO Ok, remember to do a scan manually just in case!
IF NOT %choice%==Q IF NOT %choice%==F IF NOT %choice%==N ECHO Please type the exact letter as shown (without the square brackets) and press Enter! & GOTO again
timeout /t 10 >nul
cls
ECHO The YEY-Computer-Checker has finished! Your System seems to be alright!
ECHO\
ECHO The Programm will automatically close in 10s or press Enter to close immediately.
timeout /t 10
EXIT
这是伪加载栏!
仅供参考,此加载栏已连接到 Windows Defender 进程(希望如此)
@ECHO OFF
SET program=MpCmdRun.exe
TASKLIST |FIND /i "%program%" >nul
:loading
IF %ERRORLEVEL% == 0 (
ECHO Windows Defender is currently scanning!
ECHO [============]
TIMEOUT /t 1 >nul
cls
ECHO Windows Defender is currently scanning!
ECHO [========================]
TIMEOUT /t 1 >nul
cls
ECHO Windows Defender is currently scanning!
ECHO [====================================]
TIMEOUT /t 1 >nul
cls
ECHO Windows Defender is currently scanning!
ECHO [================================================]
TIMEOUT /t 1 >nul
cls
ECHO Windows Defender is currently scanning!
ECHO [============================================================]
TIMEOUT /t 1 >nul
cls
IF NOT %ERRORLEVEL% == 0 EXIT
GOTO loading
)
使用 IF ERRORLEVEL n 检查 n 或更高的错误级别,如果不正确理解,可能会导致意外行为。相反,请使用 IF %ERRORLEVEL% == n 进行精确比较。 /y 选项对于 chkdsk 无效。如果要修复磁盘上的错误,正确的选项是/f,而要定位坏扇区并恢复可读信息,请使用/r。默认情况下,批处理文件中的比较区分大小写。在 IF 语句中使用 /I 使其不区分大小写。使用 >nul 在需要时抑制输出而不指定 nobreak。
@ECHO OFF
TITLE YEY-Computer-Checker
ECHO Starting disk check...
chkdsk /f /r >nul
ECHO Disk check complete.
timeout /t 10 >nul
cls
ECHO Running system file checker...
sfc /scannow
timeout /t 10 >nul
cls
ECHO Checking system image health...
DISM /Online /Cleanup-Image /CheckHealth
timeout /t 10 >nul
cls
ECHO Scanning system image health...
DISM /Online /Cleanup-Image /ScanHealth
timeout /t 10 >nul
cls
ECHO Restoring system image health if necessary...
IF %ERRORLEVEL% NEQ 0 DISM /Online /Cleanup-Image /RestoreHealth
timeout /t 10 >nul
cls
ECHO Do you wish to do a [Q]uick Scan, a [F]ull Scan, or [N]either?
:again
set /p choice="Please enter your choice (Q, F, N): "
IF /I "%choice%"=="Q" (
"C:\Program Files\Windows Defender\MpCmdRun.exe" -Scan -ScanType 1
) ELSE IF /I "%choice%"=="F" (
"C:\Program Files\Windows Defender\MpCmdRun.exe" -Scan -ScanType 2
) ELSE IF /I "%choice%"=="N" (
ECHO Ok, remember to do a scan manually just in case!
) ELSE (
ECHO Please type the exact letter as shown (without the square brackets) and press Enter!
GOTO again
)
timeout /t 10 >nul
cls
ECHO The YEY-Computer-Checker has finished! Your System seems to be alright!
ECHO The program will automatically close in 10s or press Enter to close immediately.
timeout /t 10
EXIT
对于连接到 Windows Defender 扫描进程的伪加载栏,确保其正确处理错误级别并正确刷新输出:
@ECHO OFF
SET program=MpCmdRun.exe
:loading
TASKLIST | FIND /i "%program%" >nul
IF ERRORLEVEL 1 (
ECHO Scan complete.
EXIT
)
ECHO Windows Defender is currently scanning!
ECHO [============]
TIMEOUT /t 1 >nul
cls
GOTO loading