-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimed_shutdown.bat
46 lines (37 loc) · 947 Bytes
/
timed_shutdown.bat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
@echo off
set /p targetInput=HH:MM:SS:
for /f "tokens=1-4 delims=:" %%A in ("%targetInput%") do (
set targetHour=%%A
set targetMinute=%%B
set targetSecond=%%C
)
if "%targetSecond%"=="" (
set targetSecond=0
)
if %targetHour% gtr 23 (
echo Hour error
goto :eof
)
if %targetMinute% gtr 59 (
echo Minute error
goto :eof
)
if %targetSecond% gtr 59 (
echo Second error
goto :eof
)
for /f "tokens=1-4 delims=:. " %%A in ('time /t ^& echo %time%') do (
set hour=%%A
set minute=%%B
set second=%%C
)
set /a currentTime=%hour%*3600 + %minute%*60 + %second%
set /a targetTime=%targetHour%*3600 + %targetMinute%*60 + %targetSecond%
if %currentTime% GEQ %targetTime% (
set /a remainingSeconds=86400 - %currentTime% + %targetTime%
) else (
set /a remainingSeconds=%targetTime% - %currentTime%
)
shutdown -s -t %remainingSeconds%
pause
shutdown -a