@ECHO off
TITLE Automatic shutdown program Author: Liao Xiaoqing
:start
CLS
COLOR 1f
rem Use the COLOR command to change the color of the console output
MODE con: COLS=41 LINES=18
rem MODE statement sets the width and height of the form
set tm1=%time:~0,2%
set tm2=%time:~3,2%
set tm3=%time:~6,2%
ECHO %date% %tm1%point %tm2%minute %tm3%seconds
ECHO =========================================
ECHO Please select the operation to be performed and press Enter
ECHO ───────────────
ECHO.
ECHO 1. Timely shutdown
ECHO 2. Countdown shutdown
ECHO 3. Delete the scheduled shutdown task
ECHO 4. Check the task status
ECHO 5. Refresh the current time
ECHO 6. Restart
ECHO 7. Lock the computer
ECHO 8. Login
ECHO 9. Exit
ECHO.
:cho
SET Choice=
SET /P Choice=Select:
rem Set the character entered by the variable "Choice" as the user
IF NOT "%Choice%"=="" SET Choice=%Choice:~0,1%
rem If the input is greater than 1 bit, take the first bit, such as input 132, the return value is 1
ECHO.
IF /I "%Choice%"=="1" GOTO SetHour
IF /I "%Choice%"=="2" GOTO outtime
IF /I "%Choice%"=="3" GOTO delAt
IF /I "%Choice%"=="4" GOTO view
IF /I "%Choice%"=="5" GOTO start
IF /I "%Choice%"=="6" GOTO restart
IF /I "%Choice%"=="7" GOTO lock
IF /I "%Choice%"=="8" GOTO logoff
IF /I "%Choice%"=="9" GOTO end
rem To avoid program exceptions caused by empty return value or space, double quotes should be added to the variable.
rem Note that IF statements need double equals the number
rem If the entered character is not the above number, it will return to re-enter
ECHO selection is invalid, please re-enter
ECHO.
GOTO cho
:SetHour
CLS
ECHO.
SET ask=
SET /p ask= Whether to set it to execute shutdown commands (y/n) every day:
IF NOT "%ask%"=="" SET ask=%ask:~0,1%
IF /I "%ask%"=="y" GOTO yes
IF /I "%ask%"=="n" GOTO no
GOTO SetHour
:yes
ECHO Please specify the 24-hour standard time, the format is hours: minutes
SET shutdowntime=
SET /p shutdowntime=Input:
at %shutdowntime% /every:M,T,W,Th,F,S,Su tsshutdn 0 /delay:0 /powerdown >nul
rem set from Monday to Sunday every week, that is, every day
IF NOT errorlevel 1 GOTO ok
rem If the input is correct, execute the ok paragraph statement
ECHO %shutdowntime% is not a standard time format, please re-enter
ECHO.
GOTO yes
:no
ECHO Please specify the 24-hour standard time, the format is hours: minutes
SET shutdowntime=
SET /p shutdowntime=Input:
at %shutdowntime% tsshutdn 0 /delay:0 /powerdown >nul
IF NOT errorlevel 1 GOTO ok
ECHO %shutdowntime% is not a standard time format, please re-enter
ECHO.
GOTO no
:ok
ECHO.
SET h=%shutdowntime:~1,1%
SET ah=%shutdowntime:~0,1%
SET am=%shutdowntime:~2,2%
SET bh=%shutdowntime:~0,2%
SET bm=%shutdowntime:~3,2%
IF "%h%"==":" (
SET HM=%ah%time%am%points
) ELSE (
SET HM=%bh%%bm% points)
rem If you enter h:mm, then HM=h hour mm minute, otherwise HM=hh hour mm minute
IF /I "%ask%"=="y" ECHO The system will be closed at %HM% per day
IF /I "%ask%"=="n" ECHO The system will be closed at %HM%
ECHO is set up! Press any key to continue...
PAUSE >nul
GOTO start
:outtime
CLS
ECHO.
ECHO Please enter the countdown seconds
ECHO ────────
ECHO (You need to cancel after setting, click "OK" and press Ctrl+C twice)
SET timed=
SET /p timed=Input:
tsshutdn %timed% /delay:0 /powerdown >nul
IF not errorlevel 1 GOTO ok
ECHO %timed% is an invalid shutdown time, please re-enter
ECHO.
GOTO outtime
:delAt
cls
echo.
at /del /y
echo The timing shutdown task has been cancelled, press any key to continue...
pause >nul
GOTO start
:view
MODE con: COLS=85 LINES=18
COLOR 70
ECHO.
at
ECHO Press any key to continue...
PAUSE >nul
GOTO start
:restart
shutdown -r -t 0
:lock
,LockWorkStation
goto start
:logoff
logoff
:end
exit
TITLE Automatic shutdown program Author: Liao Xiaoqing
:start
CLS
COLOR 1f
rem Use the COLOR command to change the color of the console output
MODE con: COLS=41 LINES=18
rem MODE statement sets the width and height of the form
set tm1=%time:~0,2%
set tm2=%time:~3,2%
set tm3=%time:~6,2%
ECHO %date% %tm1%point %tm2%minute %tm3%seconds
ECHO =========================================
ECHO Please select the operation to be performed and press Enter
ECHO ───────────────
ECHO.
ECHO 1. Timely shutdown
ECHO 2. Countdown shutdown
ECHO 3. Delete the scheduled shutdown task
ECHO 4. Check the task status
ECHO 5. Refresh the current time
ECHO 6. Restart
ECHO 7. Lock the computer
ECHO 8. Login
ECHO 9. Exit
ECHO.
:cho
SET Choice=
SET /P Choice=Select:
rem Set the character entered by the variable "Choice" as the user
IF NOT "%Choice%"=="" SET Choice=%Choice:~0,1%
rem If the input is greater than 1 bit, take the first bit, such as input 132, the return value is 1
ECHO.
IF /I "%Choice%"=="1" GOTO SetHour
IF /I "%Choice%"=="2" GOTO outtime
IF /I "%Choice%"=="3" GOTO delAt
IF /I "%Choice%"=="4" GOTO view
IF /I "%Choice%"=="5" GOTO start
IF /I "%Choice%"=="6" GOTO restart
IF /I "%Choice%"=="7" GOTO lock
IF /I "%Choice%"=="8" GOTO logoff
IF /I "%Choice%"=="9" GOTO end
rem To avoid program exceptions caused by empty return value or space, double quotes should be added to the variable.
rem Note that IF statements need double equals the number
rem If the entered character is not the above number, it will return to re-enter
ECHO selection is invalid, please re-enter
ECHO.
GOTO cho
:SetHour
CLS
ECHO.
SET ask=
SET /p ask= Whether to set it to execute shutdown commands (y/n) every day:
IF NOT "%ask%"=="" SET ask=%ask:~0,1%
IF /I "%ask%"=="y" GOTO yes
IF /I "%ask%"=="n" GOTO no
GOTO SetHour
:yes
ECHO Please specify the 24-hour standard time, the format is hours: minutes
SET shutdowntime=
SET /p shutdowntime=Input:
at %shutdowntime% /every:M,T,W,Th,F,S,Su tsshutdn 0 /delay:0 /powerdown >nul
rem set from Monday to Sunday every week, that is, every day
IF NOT errorlevel 1 GOTO ok
rem If the input is correct, execute the ok paragraph statement
ECHO %shutdowntime% is not a standard time format, please re-enter
ECHO.
GOTO yes
:no
ECHO Please specify the 24-hour standard time, the format is hours: minutes
SET shutdowntime=
SET /p shutdowntime=Input:
at %shutdowntime% tsshutdn 0 /delay:0 /powerdown >nul
IF NOT errorlevel 1 GOTO ok
ECHO %shutdowntime% is not a standard time format, please re-enter
ECHO.
GOTO no
:ok
ECHO.
SET h=%shutdowntime:~1,1%
SET ah=%shutdowntime:~0,1%
SET am=%shutdowntime:~2,2%
SET bh=%shutdowntime:~0,2%
SET bm=%shutdowntime:~3,2%
IF "%h%"==":" (
SET HM=%ah%time%am%points
) ELSE (
SET HM=%bh%%bm% points)
rem If you enter h:mm, then HM=h hour mm minute, otherwise HM=hh hour mm minute
IF /I "%ask%"=="y" ECHO The system will be closed at %HM% per day
IF /I "%ask%"=="n" ECHO The system will be closed at %HM%
ECHO is set up! Press any key to continue...
PAUSE >nul
GOTO start
:outtime
CLS
ECHO.
ECHO Please enter the countdown seconds
ECHO ────────
ECHO (You need to cancel after setting, click "OK" and press Ctrl+C twice)
SET timed=
SET /p timed=Input:
tsshutdn %timed% /delay:0 /powerdown >nul
IF not errorlevel 1 GOTO ok
ECHO %timed% is an invalid shutdown time, please re-enter
ECHO.
GOTO outtime
:delAt
cls
echo.
at /del /y
echo The timing shutdown task has been cancelled, press any key to continue...
pause >nul
GOTO start
:view
MODE con: COLS=85 LINES=18
COLOR 70
ECHO.
at
ECHO Press any key to continue...
PAUSE >nul
GOTO start
:restart
shutdown -r -t 0
:lock
,LockWorkStation
goto start
:logoff
logoff
:end
exit