In general, we use shutdown for shutdown and restart.
Usage: shutdown [/I |/l |/s |/r |/a |/p |/h |/e] [/f]
[/M \ computer] [/t xxx] [/d [p:] xx: yy [/c "comment"]
No parameter display help. This corresponds to the type /? Is the same
/? Show Help. This is the same as not typing any options
/I displays the graphical user interface (GUI ).
This must be the first option
/L log out. This cannot be used with the/m or/d option
/S shut down the computer
/R Disable and restart the computer
/A discard the system shutdown.
This can only be used during timeout
/P shut down the local computer without timeout or warning.
This can only be used with the/d option
/H sleep the local computer.
This can only be used with the/f Option
/E. Record the cause of computer shutdown in the document
/M \ computer specifies the target computer
/T xxx sets the timeout before closing to xxx seconds.
Valid range: 0-600; default value: 30
/C "comment" comments about the reason for restarting or disabling.
Up to 127 characters allowed
/F force the running application to close without warning the user beforehand
/D [p:] xx: yy provides reasons for restarting or disabling
P indicates that the restart or shutdown is planned.
Xx is the primary cause Number (a positive integer smaller than 256)
Yy is the secondary cause Number (a positive integer smaller than 65536)
Restart
Shutdown/r/f
Shutdown
Shutdown/s/f
The following is a multi-functional edition that is suitable for bat learners.
Copy codeThe Code is as follows: @ ECHO off
TITLE automatic shutdown program Author: Liao Xiaoqing
: Start
CLS
COLOR 1f
Rem uses the COLOR command to change the console output COLOR
MODE con: COLS = 41 LINES = 18
The 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 % second
ECHO ===================================================== =
Select the operation to be performed for ECHO, and press ENTER
ECHO ── ─
ECHO.
ECHO 1. Timed Shutdown
ECHO 2. Countdown Shutdown
ECHO 3. Delete the Timed Shutdown task
ECHO 4. View task status
ECHO 5. Refresh the current time
ECHO 6. Restart
ECHO 7. Lock the computer
ECHO 8. logout
ECHO 9. Exit
ECHO.
: Cho
SET Choice =
SET/P Choice = select:
The rem setting variable "Choice" is a character entered by the user
If not "% Choice %" = "" SET Choice = % Choice :~ 0, 1%
Rem if the input is greater than 1 bit, take 1st bits. For example, if the input is 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
In order to avoid program exceptions caused by null or spaces returned, add double quotation marks outside the variable.
Rem Note: The IF statement requires a double equal sign.
Rem if the entered character is not a number above, it will return re-Input
The ECHO selection is invalid. enter a new one.
ECHO.
GOTO cho
: SetHour
CLS
ECHO.
SET ask =
SET/p ask = SET to execute the shutdown command every day (y/n ):
If not "% ask %" = "" SET ask = % ask :~ 0, 1%
IF/I "% ask %" = "y" GOTO yes
IF/I "% ask %" = "n" GOTO no
GOTO SetHour
: Yes
Specify the 24-hour Standard Time for ECHO, in the format of hour: minute
SET shutdowntime =
SET/p shutdowntime = input:
At % shutdowntime %/every: M, T, W, Th, F, S, Su tsshutdn 0/delay: 0/powerdown> nul
Rem is set to Monday to Sunday, that is, every day.
If not errorlevel 1 GOTO OK
If the input is correct, run the Statement of the OK segment.
ECHO % shutdowntime % is not the standard time format. Please try again
ECHO.
GOTO yes
: No
Specify the 24-hour Standard Time for ECHO, in the format of hour: minute
SET shutdowntime =
SET/p shutdowntime = input:
At % shutdowntime % tsshutdn 0/delay: 0/powerdown> nul
If not errorlevel 1 GOTO OK
ECHO % shutdowntime % is not the standard time format. Please try again
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 % hour % am % minute
) ELSE (
Set hm = % bh % bm % points)
Rem if h: mm is input, HM = h mm is used; otherwise, HM = hh mm is used.
IF/I "% ask %" = "y" ECHO system will be disabled at % HM % every day
IF/I "% ask %" = "n" ECHO system will be disabled at % HM %
ECHO settings complete! Press any key to continue...
PAUSE> nul
GOTO start
: Outtime
CLS
ECHO.
Please input countdown seconds for ECHO
ECHO ── ─
ECHO (to cancel 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 % indicates the shutdown time is invalid. Please enter a new one.
ECHO.
GOTO outtime
: DelAt
Cls
Echo.
At/del/y
Echo Timed Shutdown task canceled. 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
Rundll32.exe user32.dll, LockWorkStation
Goto start
: Logoff
Logoff
: End
Exit