Stop Process #1 till Process #2 completes

Topics: Archive - Deployment Scripts
Oct 5, 2014 at 2:12 PM
We have a internal add-on/software and during its installation all browser windows has to be closed and no browser has be opened again during installation.

Is it possible to stop browsers from opening/starting during another software installation but after completion this lock should be removed and browsers should be able to start on click?
Oct 6, 2014 at 3:41 PM
It most certainly is possible. I have to do the same thing, as most do, when installing Java.

Here is what I did, and made it a std across the board for my systems.

I added the following code to AppDeployToolkitExtensions.ps1 and then call the functions in the script.


Check for java


Function Test-java {
Write-Log "Testing java status..."
Try {
    If (Get-Process "java,javaw" -ErrorAction SilentlyContinue) {
        Write-Log "Java is running."
        Return $true
    Else {
        Write-Log "Java is not running."
        Return $false
Catch [Exception] {
    Write-Log "Java is not running."
    Return $false


Check for IE


Function Test-IE {
Write-Log "Testing Internet Explorer status..."
Try {
    If (Get-Process "iexplore" -ErrorAction SilentlyContinue) {
        Write-Log "Internet Explorer is running."
        Return $true
    Else {
        Write-Log "Internet Explorer is not running."
        Return $false
Catch [Exception] {
    Write-Log "Internet Explorer is not running."
    Return $false


Check for chrome


Function Test-Chrome {
Write-Log "Testing Chrome status..."
Try {
    If (Get-Process "chrome" -ErrorAction SilentlyContinue) {
        Write-Log "Chrome is running."
        Return $true
    Else {
        Write-Log "Chrome is not running."
        Return $false
Catch [Exception] {
    Write-Log "Chrome is not running."
    Return $false


Check for firefox


Function Test-firefox {
Write-Log "Testing Firefox status..."
Try {
    If (Get-Process "firefox" -ErrorAction SilentlyContinue) {
        Write-Log "Firefox is running."
        Return $true
    Else {
        Write-Log "Firefox is not running."
        Return $false
Catch [Exception] {
    Write-Log "firefox is not running."
    Return $false
Oct 6, 2014 at 3:42 PM
I also have added a section for checking pending reboots:


Check for pending restart


Function Get-PendingReboot{
Gets the pending reboot status on a local or remote computer.


This function will query the registry on a local or remote computer and determine if the
system is pending a reboot, from either Microsoft Patching or a Software Installation.
For Windows 2008+ the function will query the CBS registry key as another factor in determining
pending reboot state. "PendingFileRenameOperations" and "Auto Update\RebootRequired" are observed
as being consistant across Windows Server 2003 & 2008.

CBServicing = Component Based Servicing (Windows 2008)
WindowsUpdate = Windows Update / Auto Update (Windows 2003 / 2008)
CCMClientSDK = SCCM 2012 Clients only (DetermineIfRebootPending method) otherwise $null value
PendFileRename = PendingFileRenameOperations (Windows 2003 / 2008)

.PARAMETER ComputerName
A single Computer or an array of computer names. The default is localhost ($env:COMPUTERNAME).

A single path to send error data to a log file.

PS C:> Get-PendingReboot -ComputerName (Get-Content C:\ServerList.txt) | Format-Table -AutoSize

Computer CBServicing WindowsUpdate CCMClientSDK PendFileRename PendFileRenVal RebootPending

DC01 False False False False
DC02 False False False False
FS01 False False False False

This example will capture the contents of C:\ServerList.txt and query the pending reboot
information from the systems contained in the file and display the output in a table. The
null values are by design, since these systems do not have the SCCM 2012 client installed,
nor was the PendingFileRenameOperations value populated.

PS C:> Get-PendingReboot

Computer : WKS01
CBServicing : False
WindowsUpdate : True
CCMClient : False
PendFileRename : False
PendFileRenVal :
RebootPending : True

This example will query the local machine for pending reboot information.

PS C:> $Servers = Get-Content C:\Servers.txt
PS C:> Get-PendingReboot -Computer $Servers | Export-Csv C:\PendingRebootReport.csv -NoTypeInformation

This example will create a report that contains pending reboot information.

Component-Based Servicing:

PendingFileRename/Auto Update:

SCCM 2012/CCM_ClientSDK:

Author: Brian Wilhite
Email: Date: 08/29/2012
PSVer: 2.0/3.0
Updated: 05/30/2013
UpdNote: Added CCMClient property - Used with SCCM 2012 Clients only
Added ValueFromPipelineByPropertyName=$true to the ComputerName Parameter
Removed $Data variable from the PSObject - it is not needed
Bug with the way CCMClientSDK returned null value if it was false
Removed unneeded variables
Added PendFileRenVal - Contents of the PendingFileRenameOperations Reg Entry



# Adjusting ErrorActionPreference to stop on all errors, since using [Microsoft.Win32.RegistryKey]
# does not have a native ErrorAction Parameter, this may need to be changed if used within another
# function.
$TempErrAct = $ErrorActionPreference
$ErrorActionPreference = "Stop"
}#End Begin Script Block
#Foreach ($Computer in $ComputerName){
        # Setting pending values to false to cut down on the number of else statements
        $PendFileRename,$Pending,$SCCM = $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 $env:COMPUTERNAME

        # Making registry connection to the local/remote computer
        $RegCon = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]"LocalMachine",$env:COMPUTERNAME)

        # If Vista/2008 & Above query the CBS Reg Key
        If ($WMI_OS.BuildNumber -ge 6001){
            $RegSubKeysCBS = $RegCon.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\").GetSubKeyNames()
            $CBSRebootPend = $RegSubKeysCBS -contains "RebootPending"
            }#End If ($WMI_OS.BuildNumber -ge 6001)

        # Query WUAU from the registry
        $RegWUAU = $RegCon.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\")
        $RegWUAURebootReq = $RegWUAU.GetSubKeyNames()
        $WUAURebootReq = $RegWUAURebootReq -contains "RebootRequired"

        # Query PendingFileRenameOperations from the registry
        $RegSubKeySM = $RegCon.OpenSubKey("SYSTEM\CurrentControlSet\Control\Session Manager\")
        $RegValuePFRO = $RegSubKeySM.GetValue("PendingFileRenameOperations",$null)

        # Closing registry connection

        # If PendingFileRenameOperations has a value set $RegValuePFRO variable to $true
        If ($RegValuePFRO){$PendFileRename = $true}#End If ($RegValuePFRO)

        # 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 = @{
        $CCMClientSDK = Invoke-WmiMethod @CCMSplat
        If ($CCMClientSDK){
                If ($CCMClientSDK.ReturnValue -ne 0){Write-Warning "Error: Determine IfRebootPending returned error code $($CCMClientSDK.ReturnValue)"}#End If ($CCMClientSDK -and $CCMClientSDK.ReturnValue -ne 0)
                If ($CCMClientSDK.IsHardRebootPending -or $CCMClientSDK.RebootPending){$SCCM = $true}#End If ($CCMClientSDK.IsHardRebootPending -or $CCMClientSDK.RebootPending)
            }#End If ($CCMClientSDK)
            $SCCM = $null

        # If any of the variables are true, set $Pending variable to $true
        If ($CBSRebootPend -or $WUAURebootReq -or $SCCM -or $PendFileRename){$Pending = $true}#End If ($CBS -or $WUAU -or $PendFileRename)

        # Creating Custom PSObject and Select-Object Splat
        $SelectSplat = @{
        New-Object -TypeName PSObject -Property @{
            } | Select-Object @SelectSplat
    }#End Try
        Write-Warning "$Computer`: $_"
        # If $ErrorLog, log the file to a user specified location/path
        If ($ErrorLog){Out-File -InputObject "$env:COMPUTERNAME`,$_" -FilePath $ErrorLog -Append}#End If ($ErrorLog)              
    }#End Catch
#}#End Foreach ($Computer in $ComputerName)      
}#End Process

# Resetting ErrorActionPref
$ErrorActionPreference = $TempErrAct
}#End End
}#End Function
Oct 6, 2014 at 3:45 PM
we are a notes shop so I also added that in there if you need it. I then comment out the nsd section of there main code as I don't like how it causes notes to exit with a visible error.

Here is the code to check pending reboots:
If($CBSRebootPend -or $WUAURebootReq -or $SCCM -or $PendFileRename){Show-InstallationRestartPrompt -CountdownSeconds 5405 -CountdownNoHideSeconds 60}

Here is the IE(web browser sections): I have this under the pre-deploy section

$MsgText = "Preparing to install/update $InstallTitle.

If((Test-IE -eq $true) -or (Test-Chrome -eq $True) -or (Test-firefox -eq $True) -or (Test-Java -eq $True)){
$MsgText = $MsgText +"Please close your browser(s) and click OK."
$UserPrompt = Show-InstallationPrompt -message $MsgText -ButtonLeftText "Cancel" -ButtonRightText "OK" -Icon "Information" -MinimizeWindows $True -Timeout 900
If($UserPrompt -eq "Cancel"){Exit-Script -ExitCode "5000"}
ElseIf($UserPrompt -eq "OK"){Show-InstallationWelcome -AllowDeferCloseApps "chrome,firefox,iexplore,java" -BlockExecution -DeferTimes $PostponeTimes}
$UserPrompt = Show-InstallationPrompt -message "$MsgText" -ButtonLeftText "Cancel" -ButtonRightText "OK" -Icon "Information" -MinimizeWindows $True -ExitTimeout 900
If($UserPrompt -eq "Cancel"){Exit-Script -ExitCode "5000"}
ElseIf($UserPrompt -eq "OK"){Show-InstallationWelcome -CloseApps "chrome,firefox,iexplore,java" -silent -BlockExecution}
ElseIf(!($UserPrompt)){Show-InstallationWelcome -CloseApps "chrome,firefox,iexplore,java" -silent -BlockExecution}

Hope this helps :)