bataras
Posts: 1
Joined: Sun Jun 24, 2012 11:15 pm

AI Pro: How do I detect a reboot is pending BEFORE install?

Using AI Pro, how do I detect that a system reboot is pending and warn the user at the start of installation?

I'm installing a .net 4.0 based windows service and on some systems there can be a reboot pending (due to for example .net 4.0 being recently installed). In that case, the install physically works, but when AI attempts to start the new service at the end of installing, the service fails to start and the whole install fails.
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: AI Pro: How do I detect a reboot is pending BEFORE insta

Hello and welcome to Advanced Installer forums,

Thank you for your interest in Advanced Installer.

I'm afraid we don't have predefined support for this. However, in order to achieve what you want you can create your own custom action which will check this. Please take a look on "Determine if your PC is waiting on a pending reboot" article which could be useful for you.

If you have any questions let us know.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
clared
Posts: 1
Joined: Thu Dec 28, 2017 1:36 pm

Re: AI Pro: How do I detect a reboot is pending BEFORE install?

Hi there,

We have faced the same challange so I have created a CustomAction with an inline PowerShell script that detect and store in a property if there is a pending Reboot on the machine.

I made the following steps:
  1. I created an Installer property named "NEED_REBOOT" and set to "False"
  2. Under "Launch Conditions" I created a new item where I put ' NEED_REBOOT = "False" ' as condition and a warning message in the Description field.
  3. I created a "Run PowerShell inline script" CustomAction
  4. I moved it just before the "Paths Resolution" defined action in the "Wizard Dialogs Stage"
  5. In the Script content I used the following code:

    Code: Select all

    # Block for declaring the script parameters.
    Param(	
    	[Parameter(Position=0,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
    	[Alias("CN","Computer")]
    	[String[]]$ComputerName="$env:COMPUTERNAME",
    	[String]$ErrorLog,
    	[String]$InstallerProp="NEED_REBOOT"
    )
    
    # Your code goes here.
    Begin {  }## End Begin Script Block
    Process {
      Foreach ($Computer in $ComputerName) {
    	Try {
    	    ## Setting pending values to false to cut down on the number of else statements
    	    $CompPendRen,$PendFileRename,$Pending,$SCCM = $false,$false,$false,$false
                            
    	    ## Setting CBSRebootPend to null since not all versions of Windows has this value
    	    $CBSRebootPend = $null
    						
    	    ## Querying WMI for build version
    	    $WMI_OS = Get-WmiObject -Class Win32_OperatingSystem -Property BuildNumber, CSName -ComputerName $Computer -ErrorAction Stop
    
    	    ## Making registry connection to the local/remote computer
    	    $HKLM = [UInt32] "0x80000002"
    	    $WMI_Reg = [WMIClass] "\\$Computer\root\default:StdRegProv"
    						
    	    ## If Vista/2008 & Above query the CBS Reg Key
    	    If ([Int32]$WMI_OS.BuildNumber -ge 6001) {
    		    $RegSubKeysCBS = $WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\")
    		    $CBSRebootPend = $RegSubKeysCBS.sNames -contains "RebootPending"		
    	    }
    							
    	    ## Query WUAU from the registry
    	    $RegWUAURebootReq = $WMI_Reg.EnumKey($HKLM,"SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\")
    	    $WUAURebootReq = $RegWUAURebootReq.sNames -contains "RebootRequired"
    						
    	    ## Query PendingFileRenameOperations from the registry
    	    $RegSubKeySM = $WMI_Reg.GetMultiStringValue($HKLM,"SYSTEM\CurrentControlSet\Control\Session Manager\","PendingFileRenameOperations")
    	    $RegValuePFRO = $RegSubKeySM.sValue
    
    	    ## Query JoinDomain key from the registry - These keys are present if pending a reboot from a domain join operation
    	    $Netlogon = $WMI_Reg.EnumKey($HKLM,"SYSTEM\CurrentControlSet\Services\Netlogon").sNames
    	    $PendDomJoin = ($Netlogon -contains 'JoinDomain') -or ($Netlogon -contains 'AvoidSpnSet')
    
    	    ## Query ComputerName and ActiveComputerName from the registry
    	    $ActCompNm = $WMI_Reg.GetStringValue($HKLM,"SYSTEM\CurrentControlSet\Control\ComputerName\ActiveComputerName\","ComputerName")            
    	    $CompNm = $WMI_Reg.GetStringValue($HKLM,"SYSTEM\CurrentControlSet\Control\ComputerName\ComputerName\","ComputerName")
    
    	    If (($ActCompNm -ne $CompNm) -or $PendDomJoin) {
    	        $CompPendRen = $true
    	    }
    						
    	    ## If PendingFileRenameOperations has a value set $RegValuePFRO variable to $true
    	    If ($RegValuePFRO) {
    		    $PendFileRename = $true
    	    }
    
    	    ## Determine SCCM 2012 Client Reboot Pending Status
    	    ## To avoid nested 'if' statements and unneeded WMI calls to determine if the CCM_ClientUtilities class exist, setting EA = 0
    	    $CCMClientSDK = $null
    	    $CCMSplat = @{
    	        NameSpace='ROOT\ccm\ClientSDK'
    	        Class='CCM_ClientUtilities'
    	        Name='DetermineIfRebootPending'
    	        ComputerName=$Computer
    	        ErrorAction='Stop'
    	    }
    	    ## Try CCMClientSDK
    	    Try {
    	        $CCMClientSDK = Invoke-WmiMethod @CCMSplat
    	    } Catch [System.UnauthorizedAccessException] {
    	        $CcmStatus = Get-Service -Name CcmExec -ComputerName $Computer -ErrorAction SilentlyContinue
    	        If ($CcmStatus.Status -ne 'Running') {
    	            Write-Warning "$Computer`: Error - CcmExec service is not running."
    	            $CCMClientSDK = $null
    	        }
    	    } Catch {
    	        $CCMClientSDK = $null
    	    }
    
    	    If ($CCMClientSDK) {
    	        If ($CCMClientSDK.ReturnValue -ne 0) {
    		        Write-Warning "Error: DetermineIfRebootPending returned error code $($CCMClientSDK.ReturnValue)"          
    		    }
    		    If ($CCMClientSDK.IsHardRebootPending -or $CCMClientSDK.RebootPending) {
    		        $SCCM = $true
    		    }
    	    }
                
    	    Else {
    	        $SCCM = $null
    	    }
    
    			$needReboot = ($CompPendRen -or $CBSRebootPend -or $WUAURebootReq -or $SCCM -or $PendFileRename)					
    		 
    	    ## Set Installer Property to the reboot result
    	    AI_SetMsiProperty $InstallerProp $needReboot
    
    			Write-Output "Need Reboot: $needReboot"
    
    	} Catch {
    		$errMessage = "$(get-date -f dd-MM-yyyy[HH:mm:ss]) $Computer`: $_"
    		
    		Write-Error -Message $errMessage -Exception $_.Exception
    	    
    	    ## If $ErrorLog, log the file to a user specified location/path
    	    If ($ErrorLog) {
    	        Out-File -InputObject $errMessage -FilePath $ErrorLog -Append
    	    }				
    	}			
      }## End Foreach ($Computer in $ComputerName)			
    }## End Process
    
    End {  }## End End
  6. In the Parameters field I added two arguments (but you can also leave it empty):
    -ErrorLog "[AppDataFolder][Manufacturer]\CheckRebootConditions.log" -InstallerProp "NEED_REBOOT"
I have used and modified a little the script I found on this page: https://gallery.technet.microsoft.com/s ... y-bdb79542

I hope this will help someone else.

Best regards,

Claudio
Daniel
Posts: 8238
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: AI Pro: How do I detect a reboot is pending BEFORE install?

Hello Claudio and welcome to our forums,

Thank you for your contribution on our forums. Certainly this will be useful for another users.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”