標籤

bat (52) 作品 (38) python (21) shell (17) windows (11) 虛擬機 (11) php (10) CPP (6) KMS (6) 程式設計 (6) docker (5) 使用教學 (5) xoops (4) 公文 (4) Apache2 (3) Excel (3) juniper (3) 資料庫 (3) mysql (2) 免動手 (2) 資料結構 (2) 軟體廣播 (2) 電腦維修 (2) Android Studio (1) Apple IPAD管理 (1) Arduino (1) CSS (1) LAMP (1) NAS (1) Ubuntu (1) VHD (1) Windows Server (1) 原因 (1) 程式應用 (1) 程式積木 (1) 編輯器 (1) 雲端硬碟 (1)

2021年4月12日 星期一

只要會用滑鼠點兩下,停用與啟用Windows 10 更新

        在學校使用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 就會消失。



資料來源:

沒有留言:

張貼留言

只要點兩下,傳統右鍵選單改回Win11右鍵選單

系列文章: 1. 只要點兩下,就能將Win11 右鍵選單 回復 傳統右鍵選單 2. 只要點兩下,傳統右鍵選單改回Win11右鍵選單 上一篇提到只要點兩下,就能將Win11選單回到傳統選單。但是有沒有方法能夠回到Win11選單呢?                    ...