天天看點

windows下延時執行修改系統時間.bat檔案

windows下延時執行修改系統時間.bat檔案

完整代碼

@echo off

if "%1" == "h" goto begin
mshta vbscript:createobject("wscript.shell").run("""%~nx0"" h",0)(window.close)&&exit
:begin
REM

>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

if '%errorlevel%' NEQ '0' (

goto UACPrompt

) else ( goto gotAdmin )

:UACPrompt

echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"

echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"

"%temp%\getadmin.vbs"

exit /B

:gotAdmin

if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )

PING -n 15 127.0.0.1

echo ==========================
echo Before changetime ,time is:
date /t
time /t

echo ==========================
echo Changing time 2019-09-01 18:17:32
date 2019-09-01
time 18:17:32.11

echo ==========================
echo After change time ,time is:
date /t
time /t

ping localhost >nul
           

代碼注釋:

1、靜默執行.bat檔案

if "%1" == "h" goto begin
mshta vbscript:createobject("wscript.shell").run("""%~nx0"" h",0)(window.close)&&exit
:begin
REM
           

2、擷取管理者權限執行該.bat檔案

>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"

if '%errorlevel%' NEQ '0' (

goto UACPrompt

) else ( goto gotAdmin )

:UACPrompt

echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"

echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"

"%temp%\getadmin.vbs"

exit /B

:gotAdmin

if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
           

3、延遲15秒執行修改系統時間操作

PING -n 15 127.0.0.1
           

4、修改系統時間

echo ==========================
echo Before changetime ,time is:
date /t
time /t

echo ==========================
echo Changing time 2019-09-01 18:17:32
date 2019-09-01
time 18:17:32.11

echo ==========================
echo After change time ,time is:
date /t
time /t

ping localhost >nul
           

繼續閱讀