Skip to content

Instantly share code, notes, and snippets.

@phyoewaipaing
Created August 16, 2017 12:45
Show Gist options
  • Save phyoewaipaing/06e5dea52392cd78e9463fb3d1e872f5 to your computer and use it in GitHub Desktop.
Save phyoewaipaing/06e5dea52392cd78e9463fb3d1e872f5 to your computer and use it in GitHub Desktop.
Check if computer restart is Pending after windows update batch script
::##check if update pending reboot key exists
@echo off
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" >nul 2>&1
IF NOT %ERRORLEVEL% == 0 goto Not_Pending_Restart
echo System Reboot Pending: Yes
::##check if the time since update has been pending reboot
for /f "tokens=3,4" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" /f "RebootRequiredSince" ^| findstr "REG_SZ"') do echo Pending since: %%a %%b
for /f %%i in ('wmic qfe list ^| find "KB" /c') do echo Number of Installed Updates: %%i
goto EOF
:Not_Pending_Restart
echo System Reboot Pending: No
for /f %%i in ('wmic qfe list ^| find "KB" /c') do echo Number of Installed Updates: %%i
:EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment