在學校使用Windows 10電腦上課,卻發現正在進行更新。需要等到更新結束,重開機後才能使用電腦上課。非常不便,造成大家的困擾。希望能寫個BAT,快速對這個BAT點兩下就能停用更新或是啟用更新。
過去所寫的BAT,速度有點慢且需要系統管理員的權限。現在只要點兩下2次,系統就會停用更新與重開機。
範例檔案下載,解壓密碼demo1234
教學影片:
目的:停用Windows 10 更新
檔案名稱:StopWin10Update.bat
內容:
@echo off
REM ---------------以下是程式碼,不需更改---------------
REM :: BatchGotAdmin (Run as Admin code starts)
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
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" )
pushd "%CD%"
CD /D "%~dp0"
REM :: BatchGotAdmin (Run as Admin code ends)
REM :: Your codes should start from the following line
sc stop wuauserv
sc stop BITS
sc config wuauserv start= disabled
sc config BITS start= disabled
shutdown /r /f /T 0 -C "Reboot in 0 seconds"
目的:啟用Windows 10 更新
檔案名稱:StartWin10Update.bat
內容:
@echo off
REM ---------------以下是程式碼,不需更改---------------
REM :: BatchGotAdmin (Run as Admin code starts)
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
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" )
pushd "%CD%"
CD /D "%~dp0"
REM :: BatchGotAdmin (Run as Admin code ends)
REM :: Your codes should start from the following line
sc config wuauserv start= auto
sc config BITS start= auto
sc start wuauserv
sc start BITS
shutdown /r /f /T 0 -C "Reboot in 0 seconds"
注意事項:在Windows 10,要以系統管理員身分執行BAT。
範例檔案下載,解壓密碼demo1234
在電腦教室,想要關閉Windows10更新,需要很多步驟。希望能夠快速關閉。
檔案名稱:StopWin10Update.bat
內容:
@echo off
echo "STOP wuauserv"
sc stop wuauserv
echo "STOP wuauserv OK,STOP BITS"
sc stop BITS
echo "STOP BITS OK,Disable wuauserv"
sc config wuauserv start= disable
echo "Disable wuauserv OK,Disable BITS"
sc config BITS start= disable
echo "Disable BITS OK,reboot in 5 seconds"
PAUSE
shutdown /r /f /T 5 -C "Reboot in 5 seconds"
那要如何知道,wuauserv 與 BITS 的狀態?
檔案名稱:StatusWin10Update.BAT
內容:
@echo off
echo "wuauserv的狀態"
sc query wuauserv
echo "BITS的狀態"
sc query BITS
PAUSE
檔案名稱:StartWin10Update.bat
內容:
@echo off
echo "Enable wuauserv"
sc config wuauserv start= auto
echo "Enable wuauserv OK,Enable BITS"
sc config BITS start= auto
echo "Enable BITS OK,Start wuauserv"
sc start wuauserv
echo "STOP wuauserv OK,Sart BITS"
sc start BITS
echo "STOP BITS OK,Reboot in 5 seconds"
PAUSE
shutdown /r /f /T 5 -C "Reboot in 5 seconds"
在電腦教室,有時需要傳BAT給學生。但是又怕學生會留下這個BAT。所以希望學生執行一次,BAT就消失。
檔案名稱:DeleteSelf.bat
內容:
start del /f /q DeleteSelf.bat
執行完,DeleteSelf.bat 就會消失。
資料來源:
沒有留言:
張貼留言