Jump to content

Test-PendingReboot.au3 -- did I miss something?


rudi
 Share

Recommended Posts

Hi.

One Exchange Server always complained, that there is a "PENDING REBOOT", I would need to reboot the server first.

Searching the web I found some advices and packed them into this script.

Looks like there are other "PENDING REBOOT" reasons, as still this box wants a reboot over and over again.

Remark:
I also used ServerManager to add some minor feature (here: telnet client) followed by a reboot. Didn't help either.

<edit>

Placed the code updates and minor changes

</edit>

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=z:\test-pendingReboot.exe
#AutoIt3Wrapper_Res_Comment=Credits to Adam Betram: https://adamtheautomator.com/pending-reboot-registry/#Pending_Reboot_Flags_are_in_the_Registry
#AutoIt3Wrapper_Res_Description=Check local machine if there is a reboot pending, list reasons
#AutoIt3Wrapper_Res_Fileversion=1.0.0.5
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#AutoIt3Wrapper_Res_ProductName=Autoit Script
#AutoIt3Wrapper_Res_ProductVersion=3.3.14.5
#AutoIt3Wrapper_Res_CompanyName=IT-Beratung Rudolf Thilo, Autoit Forum "Rudi"
#AutoIt3Wrapper_Res_LegalCopyright=no copyright :-)
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1033
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Array.au3>
#include <Debug.au3>
#include <Date.au3>

; v1.0.0.1 - 2021-08-17: Zeitstempel in den Namen der Ausgabedatei übernommen, Namen umgestellt (PendingReboot statt RebootPending, passend zum Skript Namen)
; v1.0.0.2 - 2021-08-17: $RebootPending +=1 in Function CheckSubKeys() hatte gefehlt.
; v1.0.0.3 - 2021-08-17: Zeile 2 ff mit domain\user@computer und weiteren Angaben eingefügt
; v1.0.0.4 - 2021-08-17: Func UpdateExeVolatile () nachgetragen, hatte gefehlt

; Credits to Adam Bertram - drived from his powershell script to check the local machine with detailed output to file
; https://adamtheautomator.com/pending-reboot-registry/#Pending_Reboot_Flags_are_in_the_Registry

#cs
    HKLM\SOFTWARE\Microsoft\Updates UpdateExeVolatile   Value is anything other than 0
    HKLM\SYSTEM\CurrentControlSet\Control\Session Manager   PendingFileRenameOperations value exists
    HKLM\SYSTEM\CurrentControlSet\Control\Session Manager   PendingFileRenameOperations2    value exists
    HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired NA  key exists
    HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending   NA  Any GUID subkeys exist
    HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting    NA  key exists
    HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce  DVDRebootSignal value exists
    HKLM\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending  NA  key exists
    HKLM\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootInProgress   NA  key exists
    HKLM\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\PackagesPending    NA  key exists
    HKLM\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttempts NA  key exists
    HKLM\SYSTEM\CurrentControlSet\Services\Netlogon JoinDomain  value exists
    HKLM\SYSTEM\CurrentControlSet\Services\Netlogon AvoidSpnSet value exists
    HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName   ComputerName    Value ComputerName in HKLM\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName is different
#ce

$RebootPending = 0
$StrResult = ""

if @OSArch="X64" Then
    $Pre="HKLM64"
Else
    $Pre="HKLM"
EndIf

Dim $a2ValExists[0][2]
$Str4ArrAdd = $Pre & "\SYSTEM\CurrentControlSet\Control\Session Manager|PendingFileRenameOperations"
$Str4ArrAdd &= @CRLF & $Pre & "\SYSTEM\CurrentControlSet\Control\Session Manager|PendingFileRenameOperations2"
$Str4ArrAdd &= @CRLF & $Pre & "\SYSTEM\CurrentControlSet\Services\Netlogon|JoinDomain"
$Str4ArrAdd &= @CRLF & $Pre & "\SYSTEM\CurrentControlSet\Services\Netlogon|AvoidSpnSet"
$Str4ArrAdd &= @CRLF & $Pre & "\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce|DVDRebootSignal"

if @OSArch="X64" then $Str4ArrAdd=StringReplace($Str4ArrAdd,$Pre & "\",$Pre & "\")
_ArrayAdd($a2ValExists, $Str4ArrAdd)
;~ _DebugArrayDisplay($a2ValExists)

$Str2Split = $Pre & "\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" & _
        "|" & $Pre & "\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting" & _
        "|" & $Pre & "\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" & _
        "|" & $Pre & "\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootInProgress" & _
        "|" & $Pre & "\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\PackagesPending" & _
        "|" & $Pre & "\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttempts"

$aKeyExists = StringSplit($Str2Split, "|", 2)
;~ _DebugArrayDisplay($aKeyExists)


Dim $aAnySubkey[1] = [$Pre & "\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending"]
;~ _DebugArrayDisplay($aAnySubkey)


CheckUpdateExeVolatile()
CheckKeyExists()
CheckValExists()
CheckSubkeys()
CheckPCrenamed()


if $RebootPending=0 Then
    $icon = 64
    $MbTitle="No reboot is pending"
Else
    $icon = 48
    $MbTitle=$RebootPending & " reboot reasons found"
EndIf

if $RebootPending=0 then $RebootPending = "No"


$OutFile="C:\temp\" & @ComputerName & "_Test-PendingReboot-result-" & @YEAR & "-" & @MON & "-" & @MDAY & "_"& @HOUR & "h-" & @MIN & "m-" & @SEC & "s.txt"
$h=FileOpen($OutFile,2+8)
FileWriteLine($h,$RebootPending & " Reboot reasons were found in the registry")
FileWriteLine($h,@tab & "Script: " & @ScriptFullPath & " v" & FileGetVersion(@ScriptFullPath) & ", " & @LogonDomain & "\" & @UserName & "@" & @ComputerName)
FileWriteLine($h,@TAB & "This file: " & $OutFile)
FileWriteLine($h,@tab & "UNC: " & StringReplace($OutFile,"C:\temp\","\\" & @ComputerName & "\C$\temp\"))
FileWrite($h,"----------------- " & _NowCalc() & " " & @ComputerName & " -------------------")
FileWriteLine($h,$StrResult)
FileWrite($h,"---------------------------- End of File -------------------------------------")
FileClose($h)
ShellExecute($OutFile)
Sleep(1000)

MsgBox($icon,$MbTitle,$RebootPending & " Reboot reasons were found in the registry",30)

Func CheckUpdateExeVolatile()
    Local $key=$Pre & "\SOFTWARE\Microsoft\Updates"
    Local $Val="UpdateExeVolatile"
    Local $Result = RegRead($key,$val)
    switch @error
        case 0
            if $Result = 0 Then
                $StrResult &= @CRLF & @TAB & $key & ", " & $val & " = 0 (okay)"
            Else
                $StrResult &= @CRLF & "not null: " & $key & ", " & $val & " = " & $Result & " (reboot pending)"
            EndIf
        case Else
            $StrResult &= @CRLF & @TAB &"Key / Val not found: " & $key & ", " & $val  & " (okay)"
    EndSwitch

EndFunc


Func CheckValExists()
    Local $v, $Result,$key,$Val
    For $v = 0 To UBound($a2ValExists) - 1
        $key=$a2ValExists[$v][0]
        $val=$a2ValExists[$v][1]
        $Result = RegRead($key, $val)
        If @error Then
            $StrResult &= @CRLF & @TAB & "Value not found: " & $key & ", " & $Val & " (okay)"
        Else
            $StrResult &= @CRLF & "Value found: (reboot pending)"
            $StrResult &= @CRLF & @TAB & "Key:  " & $key
            $StrResult &= @CRLF & @TAB & "Val:  " & $Val
            $StrResult &= @CRLF & @TAB & "Type: " & RegTypeText(@extended)
            $StrResult &= @CRLF & @TAB & "Content:"
            $StrResult &= @CRLF & @TAB & "---------------------------------------------------------------"
            $StrResult&= @CRLF & @TAB & StringReplace($Result,@LF,@CRLF & @TAB)
            $StrResult &= @CRLF & @TAB & "---------------------------------------------------------------"
            $RebootPending+=1
        EndIf
    Next
EndFunc   ;==>CheckValExists

Func CheckKeyExists()
    Local $key, $Result
    For $key In $aKeyExists
        $Result = RegRead($key, "")
        If @error Then
            $StrResult &= @CRLF & @TAB & "Key not found: " & $key & " (okay)"
        Else
            $StrResult &= @CRLF & "Key exists: " & $key & " (reboot pending)"
        EndIf
    Next
EndFunc   ;==>CheckKeyExists

Func CheckSubkeys()
    Local $MainKey, $SubKey
    For $MainKey In $aAnySubkey
        $Ptr = 0
        While 1
            $Ptr += 1
            $SubKey = RegEnumKey($MainKey, $Ptr)
            If @error Then
                If $Ptr = 1 Then $StrResult &= @CRLF & @TAB & "No subkeys: " & $MainKey & " (okay)"
                ExitLoop
            Else
                $StrResult &= @CRLF & "Subkey found: " & $MainKey & "\" & $SubKey & " (reboot pending)"
                $RebootPending+=1
            EndIf
        WEnd
    Next
EndFunc   ;==>CheckSubkeys

Func CheckPCrenamed()
    $NameActiveKey = $Pre & "\SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName"
    $NameKey = $Pre & "\SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName"
    $NameVal = "ComputerName"
    $NameNow = RegRead($NameActiveKey, $NameVal)
    $Name = RegRead($NameKey, $NameVal)
    If $Name = $NameNow Then
        $StrResult &= @CRLF & @TAB & "Computername was not changed: """ & $Name & """ (okay)"
    Else
        $StrResult &= @CRLF & "Computername changed! " & $NameNow & " --> " & $Name & " (reboot pending)"
        $RebootPending += 1
    EndIf
EndFunc   ;==>PCrenamed


Func RegTypeText($_int)
    Switch $_int
        Case 0
            Return "REG_NONE"
        Case 1
            Return "REG_SZ"
        Case 2
            Return "REG_EXPAND_SZ"
        Case 3
            Return "REG_BINARY"
        Case 4
            Return "REG_DWORD"
        Case 5
            Return "REG_DWORD_BIG_ENDIAN"
        Case 6
            Return "REG_LINK"
        Case 7
            Return "REG_MULTI_SZ"
        Case 8
            Return "REG_RESOURCE_LIST"
        Case 9
            Return "REG_FULL_RESOURCE_DESCRIPTOR"
        Case 10
            Return "REG_RESOURCE_REQUIREMENTS_LIST"
        Case 11
            Return "REG_QWORD"
        Case Else
            Return "Unknown REG_TYPE, Autoit Value = " & $_int
    EndSwitch
    #cs defined in AutoitConstants.au3
        ; Reg Value type Constants
        Global Const $REG_NONE = 0
        Global Const $REG_SZ = 1
        Global Const $REG_EXPAND_SZ = 2
        Global Const $REG_BINARY = 3
        Global Const $REG_DWORD = 4
        Global Const $REG_DWORD_LITTLE_ENDIAN = 4
        Global Const $REG_DWORD_BIG_ENDIAN = 5
        Global Const $REG_LINK = 6
        Global Const $REG_MULTI_SZ = 7
        Global Const $REG_RESOURCE_LIST = 8
        Global Const $REG_FULL_RESOURCE_DESCRIPTOR = 9
        Global Const $REG_RESOURCE_REQUIREMENTS_LIST = 10
        Global Const $REG_QWORD = 11
        Global Const $REG_QWORD_LITTLE_ENDIAN = 11
    #ce defined in AutoitConstants.au3
EndFunc   ;==>RegTypeText

 

this is an example for a possible output

1 Reboot reasons were found in the registry
    Script: Z:\test-pendingReboot.exe v1.0.0.4, AD\Rudi@WX-0111
    This file: C:\temp\WX-0111_Test-PendingReboot-result-2021-08-18_11h-21m-50s.txt
    UNC: \\WX-0111\C$\temp\WX-0111_Test-PendingReboot-result-2021-08-18_11h-21m-50s.txt
----------------- 2021/08/18 11:21:50 WX-0111 -------------------
    Key / Val not found: HKLM64\SOFTWARE\Microsoft\Updates, UpdateExeVolatile (okay)
    Key not found: HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired (okay)
    Key not found: HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\PostRebootReporting (okay)
    Key not found: HKLM64\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending (okay)
    Key not found: HKLM64\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootInProgress (okay)
    Key not found: HKLM64\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\PackagesPending (okay)
    Key not found: HKLM64\SOFTWARE\Microsoft\ServerManager\CurrentRebootAttempts (okay)
Value found: (reboot pending)
    Key:  HKLM64\SYSTEM\CurrentControlSet\Control\Session Manager
    Val:  PendingFileRenameOperations
    Type: REG_MULTI_SZ
    Content:
    ---------------------------------------------------------------
    \??\C:\WINDOWS\system32\spool\PRTPROCS\x64\1_hpcpp160.dll
    
    \??\C:\Program Files (x86)\Microsoft\EdgeUpdate\1.3.147.37
    
    ---------------------------------------------------------------
    Value not found: HKLM64\SYSTEM\CurrentControlSet\Control\Session Manager, PendingFileRenameOperations2 (okay)
    Value not found: HKLM64\SYSTEM\CurrentControlSet\Services\Netlogon, JoinDomain (okay)
    Value not found: HKLM64\SYSTEM\CurrentControlSet\Services\Netlogon, AvoidSpnSet (okay)
    Value not found: HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce, DVDRebootSignal (okay)
    No subkeys: HKLM64\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Services\Pending (okay)
    Computername was not changed: "WX-0111" (okay)
---------------------------- End of File -------------------------------------

 

cu, Rudi.

Edited by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...