公司里需要,每天都要手动关掉那两台服务器,真麻烦。
于是写了个小脚本。
需要把 XP或2003系统里的 shutdown.exe 文件配合。
总共有4个文件:
1 )begin.bat
内容:
@echo off
start hide.vbs
exit
start hide.vbs
exit
引用 hide.vbs 文件,在系统启动时启动;
2)hide.vbs
内容:
CreateObject("WScript.Shell").Run "ShutDownComputer.bat",0
引用 shutdowncomputer.bat文件,该文件在使运行时隐藏窗口。
3)shutdown.exe
在系统里找到它。
4)ShutDownComputer.bat
核心文件
::close command prompt
@echo off
@echo off
::Set the default times
set Default_hour=17
set Default_minute=16
set Default_second=30
::Cycling.
:CopeHour
cls
set Default_hour=17
set Default_minute=16
set Default_second=30
::Cycling.
:CopeHour
cls
::prompt the time of closing computer
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo ~~~~~Computer closed at 17:16~~~~~~~~~~~
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo ~~~~~电脑将于下午五点十六分关闭~~~~~~~
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo ~~~~~Computer closed at 17:16~~~~~~~~~~~
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo ~~~~~电脑将于下午五点十六分关闭~~~~~~~
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
::separate the time,get the hour, minute, second
for /f "tokens=1,2,3* delims=:" %%i in ("%time%") do (
::echo %%i %%j %%k
set C_hour=%%i
set C_minute=%%j
set C_MX_second=%%k)
::separate the MX second,get the second,mirsecond
for /f "tokens=1,2* delims=. " %%m in ("%C_MX_second%") do (
::echo %%m
set C_second=%%m)
for /f "tokens=1,2,3* delims=:" %%i in ("%time%") do (
::echo %%i %%j %%k
set C_hour=%%i
set C_minute=%%j
set C_MX_second=%%k)
::separate the MX second,get the second,mirsecond
for /f "tokens=1,2* delims=. " %%m in ("%C_MX_second%") do (
::echo %%m
set C_second=%%m)
echo ~~ 当前时间: %Date% %C_hour%:%C_minute% ~
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo ~~~~~~~~~~~~~~~~~~~~
echo ~请不要关闭当前窗口~
echo ~~~~~~~~~~~~~~~~~~~~
echo Coping...
echo ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
echo ~~~~~~~~~~~~~~~~~~~~
echo ~请不要关闭当前窗口~
echo ~~~~~~~~~~~~~~~~~~~~
echo Coping...
set /a C_minute=%C_minute%+1
:CopeMinute
for /f "tokens=1,2,3* delims=:" %%x in ("%time%") do (
::echo %%x %%y %%z
set CC_minute=%%y
set CC_MX_second=%%z)
::separate the MX second,get the second,mirsecond
for /f "tokens=1,2* delims=. " %%o in ("%CC_MX_second%") do (
::echo %%o %%p
set CC_second=%%o
set CC_mirosecond=%%p)
:CopeMinute
for /f "tokens=1,2,3* delims=:" %%x in ("%time%") do (
::echo %%x %%y %%z
set CC_minute=%%y
set CC_MX_second=%%z)
::separate the MX second,get the second,mirsecond
for /f "tokens=1,2* delims=. " %%o in ("%CC_MX_second%") do (
::echo %%o %%p
set CC_second=%%o
set CC_mirosecond=%%p)
if %CC_minute% GEQ %C_minute% (
goto ShutComputer) else (
::echo %C_hour%:%C_minute% %CC_second%.%CC_mirosecond%
goto CopeMinute)
goto ShutComputer) else (
::echo %C_hour%:%C_minute% %CC_second%.%CC_mirosecond%
goto CopeMinute)
::check times for shutdown the computer
:ShutComputer
:ShutComputer
if %C_hour% lss %Default_hour% (
::echo %C_hour% 1
::pause
goto CopeHour) else (
if %C_minute% lss %Default_minute% (
::echo %C_hour%:%C_minute% 3
::pause
goto CopeHour) else (
::echo %C_hour%:%C_minute% 4
start shutdown.exe -s -t 20
exit
)
)
start shutdown.exe -a
exit
::pause
cls
goto CopeHour
::echo %C_hour% 1
::pause
goto CopeHour) else (
if %C_minute% lss %Default_minute% (
::echo %C_hour%:%C_minute% 3
::pause
goto CopeHour) else (
::echo %C_hour%:%C_minute% 4
start shutdown.exe -s -t 20
exit
)
)
start shutdown.exe -a
exit
::pause
cls
goto CopeHour
转载于:https://blog.51cto.com/everyhelp/63158