Notices: This section not yet converted to new layout. Download stats are rolling back out.

Chocolatey Preinstaller Checks Extension

0.0.2.1

Package test results are passing.

This package is exempt from moderation. While it is likely safe for you, there is more risk involved.


choco://chocolatey-preinstaller-checks.extension
To use choco:// protocol URLs, install (unofficial) choco:// Protocol support


Screenshot of chocolatey-preinstaller-checks.extension

Chocolatey Preinstaller Checks Extension is a Chocolatey extension that intercepts and runs checks before installing or uninstalling a program. This extension will start working automatically once installed and does NOT need to be implemented by package creators/maintainers. Chocolatey Preinstaller Checks Extension is meant to be installed and used directly by Chocolatey end users.

PURPOSE:

This extension attempts to head off problems related to:

Chocolatey Preinstaller Checks Extension's main purpose is to fend off specific types of problems before they occur. Currently Chocolatey (choco.exe) is not multi-instance friendly. If you try to install or uninstall packages using choco.exe in two Command Prompts at the same time, strange (bad!) things may occur. Chocolatey Preinstaller Checks Extension can avoid these strange (bad!) things by intercepting calls to install and uninstall programs and warn about the situation, wait for previous instances to finish, or abort; totally configurable. Chocolatey Preinstaller Checks Extension also checks Windows Installer to see if it's busy and will warn, make MSI installer and uninstaller programs wait until Windows Installer has finished processing the other program, or abort. Chocolatey Preinstaller Checks Extension only runs before PROGRAM installations and uninstallations. It does not perform any functions related to portable packages or other choco commands.

FEATURES:

  • Chocolatey Preinstaller Checks Extension is completely configurable to warn, wait, or abort.
  • Chocolatey Preinstaller Checks Extension will check if there is a pending reboot and warn you about it if so.
  • Chocolatey Preinstaller Checks Extension will check if Windows Installer is already running and warn, wait for it to finish, or abort.
  • Chocolatey Preinstaller Checks Extension will check if there are instances of choco.exe already running and warn, wait for it to finish, or abort.

PACKAGE NOTES


Click here to Patreon-ize the package maintainer.


To install Chocolatey Preinstaller Checks Extension, run the following command from the command line or from PowerShell:

C:\> choco install chocolatey-preinstaller-checks.extension

To upgrade Chocolatey Preinstaller Checks Extension, run the following command from the command line or from PowerShell:

C:\> choco upgrade chocolatey-preinstaller-checks.extension

Files

Hide
  • extensions\Chocolatey-Preinstaller-Checks.extension.psm1 Show
    # chocolatey-preinstaller-checks.extension v0.0.2 by Bill Curran AKA BCURRAN3 - 2018 Copyleft Bill Curran
    
    $scriptRoot = Split-Path -Path $MyInvocation.MyCommand.Definition
     
    $publicFunctions = @(
        'Get-chocoInstanceCounts',
    	'Get-chocoStatus',
    	'Get-PendingRebootStatus',
        'Get-WindowsInstallerStatus',
    	'Start-PreinstallChecks',
    	'Start-PreuninstallChecks'
    )
    
    Get-ChildItem -Path "$scriptRoot\*.ps1" | ForEach-Object { . $_ }
    Export-ModuleMember -Function $publicFunctions
    
    Set-Alias Install-ChocolateyInstallPackage Start-PreinstallChecks -Force -Scope Global
    Set-Alias Uninstall-ChocolateyPackage Start-PreuninstallChecks -Force -Scope Global	
    
  • extensions\Chocolatey-Preinstaller-Checks.xml Show
    <?xml version="1.0"?>
    <Settings>
      <global>
        <AbortOnMultiples>false</AbortOnMultiples>
      </global>
      <chocoStatus>
        <WaitOnMultiple>true</WaitOnMultiple>
    	<PauseSeconds>5</PauseSeconds>
    	<AbortSeconds></AbortSeconds>
      </chocoStatus>
      <PendingRebootStatus>
        <action>warn</action>
      </PendingRebootStatus>
      <WindowsInstallerStatus>
        <WaitOnMultiple>true</WaitOnMultiple>
    	<PauseSeconds>5</PauseSeconds>
        <AbortSeconds></AbortSeconds>	
      </WindowsInstallerStatus>
    </Settings>
    
    <!--
    Chocolatey-Preinstaller-Checks.xml preferences notes:
    
    AbortOnMultiples - true  = abort install/upgrades due to multiple instances of choco or Windows Installer
                     - false = warn only and continue as normal
    WaitOnMultiple   - true = pause for number of PauseSeconds in hope the other instance(s) will finish
                     - false = warn only and continue as normal
    PauseSeconds     - number of seconds to wait and then retry
    AbortSeconds     - not implemented yet
    PendingRebootStatus - action to perform when PRS is true, NOT IMPLEMENTED YET, possibly warn (continue), abort, retry (later), reboot
    
    -->
  • extensions\Get-chocoInstanceCounts.ps1 Show
    # chocolatey-preinstaller-checks.extension v0.0.2 by Bill Curran AKA BCURRAN3 - 2018 Copyleft Bill Curran
    # modification created by Michel Buczynski AKA MikeBoutch 
    # \ProgramData\chocolatey\bin\choco.exe (in path) is a shim and \ProgramData\chocolatey\choco.exe actual (not in path)
    # SelfServe mode imply a background choco.exe with chocolatey-agent as parent and
    #    a forground choco.exe with a shim as parent
    # Get the current instance choco.exe (so we a count of 1 already)
    # get all instances of choco.exe 
    #    Dont count who has chocholatey-agent.exe has parent since they a foreground pair of shim and choco.exe running
    #    Count only those that have a shim or chocolatey-management-service as parent
    
    function Get-chocoInstanceCounts{
        
        $chocoCommands='chocolatey', 'choco', 'cinst', 'clist',  'cpack', 'cpush', 'cup', 'cuninst', 'cver', 'chocolatey-management-service' 
      
        Write-verbose "Current Process: $($PID)"
        if ($(Get-Process -Id (Get-CimInstance -Class Win32_Process -Verbose:$false -Filter "ProcessID=$($PID)").ParentProcessId).ProcessName -eq 'chocolatey-agent'){
            Write-verbose "   Running in SelfServe (background mode)"
        }
      
        Write-verbose "Searching for choco.exe process"
        $counts=0
        Get-Process -ea silentlycontinue -Name choco| % {
          $_Cim=Get-CimInstance -Class Win32_Process -Verbose:$false -Filter "ProcessID=$($_.Id)"
          $_Parent=Get-Process -Id $_Cim.ParentProcessId
          $_ParentCim=Get-CimInstance -Class Win32_Process -Verbose:$false -Filter "ProcessID=$($_Parent.Id)"
          Write-Verbose "$($_.Id): ``$($_Cim.CommandLine)`` --> $($_Parent.Id): ``$($_ParentCim.CommandLine)``"
          if ($chocoCommands.contains($_Parent.ProcessName)) {
            Write-Verbose "$($_.Id) is actual choco process"
            $counts+=1 
          } elseif ($_Parent.ProcessName -eq 'chocolatey-agent'){
            Write-Verbose "$($_.Id) is Chocolatey in background mode"
            #count only choco.exe running in foreground   
          } else {
            Write-Verbose "$($_.Id) is probably a shim of choco.exe"
          }
        }
        Write-Verbose "choco.exe instance count is $($counts)"
      
        return $counts
      }
  • extensions\Get-WindowsInstallerStatus.ps1 Show
    # chocolatey-preinstaller-checks.extension v0.0.2 by Bill Curran AKA BCURRAN3 - 2018 Copyleft Bill Curran
    # Get-WindowsInstallerStatus.ps1 - checks for multiple instances of Windows Installer running and warns or aborts
    # See/Edit Chocolatey-Preinstaller-Checks.xml for options
    # If this extension stops your packages from becoming lost and unmanaged, consider becoming a patron of me at https://www.patreon.com/bcurran3 :)
    
    function Get-WindowsInstallerStatus{
    $msiexecInstances = @(Get-Process -ea silentlycontinue msiexec).count
    
    # Import preferences
    $xml   = 'Chocolatey-Preinstaller-Checks.xml'  
    [xml]$ConfigFile = Get-Content "$env:ChocolateyInstall\extensions\chocolatey-preinstaller-checks\$xml"  
    $AbortOnMultiples= $ConfigFile.Settings.global.AbortOnMultiples
    $WaitOnMultiple  = $ConfigFile.Settings.WindowsInstallerStatus.WaitOnMultiple
    $PauseSeconds    = $ConfigFile.Settings.WindowsInstallerStatus.PauseSeconds
    
    if ($msiexecInstances -gt 1)
       {
        $LoopMePlease=0
        while ($msiexecInstances -gt 1)
    	{
         If ($AbortOnMultiples -eq $true)
             {
    	      Write-Host "  * WARNING: Windows Installer IS currently running. Aborting install of $env:packageName!" -foreground red
    	      $global:CPCEAbort = $true
    	      return
    	     }
         If ($WaitOnMultiple -eq $false)
    	     {
    	      Write-Host "  * WARNING: Windows Installer IS currently running" -foreground red
    	      return
    	     }
         if ($LoopMePlease % 2 -eq 0) {$color="Red"} else {$color="DarkRed"}
         Write-Host -NoNewLine "`r  * WARNING: Windows Installer IS currently running. Pausing $PauseSeconds seconds...(x$LoopMePlease)" -foreground $color
    	 Start-Sleep -seconds $PauseSeconds
         $msiexecInstances = @(Get-Process -ea silentlycontinue msiexec).count
    	 $LoopMePlease++
         $WaitDisplayed=$true
    	}
       } else {
         Write-Host "  * Windows Installer IS NOT currently running" -foreground green
    	}
    if ($WaitDisplayed) {Write-Host ""}
    }
    
  • extensions\Start-PreinstallChecks.ps1 Show
    # chocolatey-preinstaller-checks.extension v0.0.2 by Bill Curran AKA BCURRAN3 - 2018 Copyleft Bill Curran
    # Start-PreinstallChecks.ps1 - aliased as Install-ChocolateyInstallPackage to intercept and run before Install-ChocolateyInstallPackage then returns original functionality and passes on to install the package
    # See/Edit Chocolatey-Preinstaller-Checks.xml for options
    # If this extension stops your packages from becoming lost and unmanaged, consider becoming a patron of me at https://www.patreon.com/bcurran3 :)
    
    function Start-PreInstallChecks{
    $CheckLicense = "$env:ChocolateyInstall\license\chocolatey.license.xml"
    
    Write-Host "PRE-INSTALLATION CHECKS:" -foreground magenta
    Get-PendingRebootStatus
    Get-WindowsInstallerStatus
    Get-chocoStatus
    if ($global:CPCEAbort -eq $true){ throw }
    
    # support for chocolatey-toast-notifications.extension 
    if (Get-Command Install-ChocolateyInstallPackageWithToastNotification -ErrorAction SilentlyContinue){
       return
      } else {
        # Remove alias for normal operations and call Install-ChocolateyInstallPackage actual
        Remove-Item alias:\Install-ChocolateyInstallPackage 
        if ($env:ChocolateyLicenseValid -eq $true) {
           Set-Alias Install-ChocolateyInstallPackage Install-ChocolateyInstallPackageCmdlet -Force -Scope Global
          }
    	Install-ChocolateyInstallPackage @args 
       }
    }
    
    
    
    ##IGNORE - NOT USED (I don't want to delete yet.)
    
    # Automatic clean-up if package install/upgrade was purposely aborted due to multiple instances of either Chocolatey or Windows Installer running
    # default=false, only occurs when $AbortOnMultiples in XML config file is set to true
    
    #if ($global:CPCEAbort -eq $true)
    #    {
    #	 if (Test-Path $env:ChocolateyInstall\lib-bkp\$env:packageName)
    #	    {
             # If the package is an upgrade, delete the newly downloaded package files and move the old package files back
    		 # This prevents Chocolatey from "loosing" management of package
    #		 Remove-Item $env:ChocolateyInstall\lib\$env:packageName -Recurse -Force -ErrorAction SilentlyContinue
    #		 Move-Item -Path $env:ChocolateyInstall\lib-bkp\$env:packageName -Destination $env:ChocolateyInstall\lib -Force -ErrorAction SilentlyContinue
    #		} else {
    #          # If the package is a new install, delete the package files so the package installation aborts
    #		  Remove-Item $env:ChocolateyInstall\lib\$env:packageName -Recurse -Force -ErrorAction SilentlyContinue
    #		}
    #	 return
    #    } else { 
          # calling Install-ChocolateyInstallPackage actual
    #	  Install-ChocolateyInstallPackage @args 
    #	}
    #}
    
  • extensions\Start-PreuninstallChecks.ps1 Show
    # chocolatey-preinstaller-checks.extension v0.0.2 by Bill Curran AKA BCURRAN3 - 2018 Copyleft Bill Curran
    # Start-PreuninstallChecks.ps1 - aliased as Uninstall-ChocolateyPackage to intercept and run before Uninstall-ChocolateyPackage then returns original functionality and passes on to uninstall the package
    # See/Edit Chocolatey-Preinstaller-Checks.xml for options
    # If this extension stops your packages from becoming lost and unmanaged, consider becoming a patron of mine at https://www.patreon.com/bcurran3 :)
    
    function Start-PreuninstallChecks{
    Write-Host "PRE-UNINSTALLATION CHECKS:" -foreground magenta
    Get-PendingRebootStatus
    Get-WindowsInstallerStatus
    Get-chocoStatus
    if ($global:CPCEAbort -eq $true){ throw }
    
    # support for chocolatey-toast-notifications.extension 
    if (Get-Command Uninstall-ChocolateyPackageWithToastNotification -ErrorAction SilentlyContinue){
       return
      } else {
        # Remove alias for normal operations and call Uninstall-ChocolateyPackage actual
        Remove-Item alias:\Uninstall-ChocolateyPackage
    	Uninstall-ChocolateyPackage @args
       }
    }
    
  • extensions\Get-PendingRebootStatus.ps1 Show
    # chocolatey-preinstaller-checks.extension v0.0.2 by Bill Curran AKA BCURRAN3 - 2018 Copyleft Bill Curran
    # Get-PendingRebootStatus.ps1 - warns if Windows has a pending reboot
    # See/Edit Chocolatey-Preinstaller-Checks.xml for options
    # If this extension stops your packages from becoming lost and unmanaged, consider becoming a patron of me at https://www.patreon.com/bcurran3 :)
    
    function Get-PendingRebootStatus{
    # thanks to http://ilovepowershell.com/2015/09/10/how-to-check-if-a-server-needs-a-reboot/
    
    $RebootStatus=$false
    if (Get-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" -ErrorAction SilentlyContinue) { $RebootStatus=$true }
    if (Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" -ErrorAction SilentlyContinue) { $RebootStatus=$true }
    if (Get-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" -Name PendingFileRenameOperations -ErrorAction SilentlyContinue) { $RebootStatus=$true }
     try { 
       $util = [wmiclass]"\\.\root\ccm\clientsdk:CCM_ClientUtilities"
       $status = $util.DetermineIfRebootPending()
       if(($status -ne $null) -and $status.RebootPending){
         RebootStatus=$true
       }
     }catch{}
    
    if ($RebootStatus -eq $true){
         Write-Host "  * WARNING: Pending reboot found." -foreground red 
       } else {
         Write-Host "  * Pending reboot NOT found." -foreground green
       }
    }
  • extensions\Get-chocoStatus.ps1 Show
    # chocolatey-preinstaller-checks.extension v0.0.2 by Bill Curran AKA BCURRAN3 - 2018 Copyleft Bill Curran
    # Get-chocoStatus.ps1 - checks for multiple instances of Chocolatey running and warns or aborts
    # See/Edit Chocolatey-Preinstaller-Checks.xml for options
    # If this extension stops your packages from becoming lost and unmanaged, consider becoming a patron of me at https://www.patreon.com/bcurran3 :)
    
    function Get-chocoStatus{
    
    # Import preferences
    $xml              = 'Chocolatey-Preinstaller-Checks.xml'  
    [xml]$ConfigFile  = Get-Content "$env:ChocolateyInstall\extensions\chocolatey-preinstaller-checks\$xml"  
    $AbortOnMultiples = $ConfigFile.Settings.global.AbortOnMultiples
    $WaitOnMultiple   = $ConfigFile.Settings.chocoStatus.WaitOnMultiple
    $PauseSeconds     = $ConfigFile.Settings.chocoStatus.PauseSeconds
    #$AbortSeconds     = $ConfigFile.Settings.chocoStatus.AbortSeconds
    
    $chocoInstances = (Get-chocoInstanceCounts)
    
    if ($chocoInstances -gt 2)
        {
    	 $LoopMePlease=0
    	 # exclude current instance from status report
         while ($chocoInstances -gt 1)
         {
    	  If ($AbortOnMultiples -eq $true)
              {
    	       Write-Host "  * WARNING: $($chocoInstances-1) other instance(s) of choco.exe actual found running. Aborting install of $env:packageName!" -foreground red
    		   $global:CPCEAbort = $true
    		   return
    	      }
    	  If ($WaitOnMultiple -eq $false)
              {
    	       Write-Host "  * WARNING: $($chocoInstances-1) other instance(s) of choco.exe actual found running." -foreground red
    		   return
    	      }
          if ($LoopMePlease % 2 -eq 0) {$color="Red"} else {$color="DarkRed"}
          Write-Host -NoNewLine "`r  * WARNING: $($chocoInstances-1) other instance(s) of choco.exe actual found running. Pausing $PauseSeconds seconds...(x$LoopMePlease)" -foreground $color
    	  Start-Sleep -seconds $PauseSeconds
          $chocoInstances = (Get-chocoInstanceCounts)
    	  $LoopMePlease++
          $WaitDisplayed=$true
    	 }
        } else {
    	  Write-Host "  * choco.exe IS NOT running multiple instances." -foreground green
    	}
    if ($WaitDisplayed) {Write-Host ""}
    }
    
    

Virus Scan Results

In cases where actual malware is found, the packages are subject to removal. Software sometimes has false positives. Moderators do not necessarily validate the safety of the underlying software, only that a package retrieves software from the official distribution point and/or validate embedded software against official distribution point (where distribution rights allow redistribution).

Chocolatey Pro provides runtime protection from possible malware.

Dependencies

Package Maintainer(s)

Software Author(s)

  • Bill Curran

Copyright

Copyleft Bill Curran

Tags

Release Notes

  • If two instances of choco.exe run within 5 seconds (or configured check time) of each other, they will most likely loop forever or until commandExecutionTimeoutSeconds.

CHANGE LOG:

  • 0.0.2.1 - Added dependencies to package, no updates to actual extension.
  • 0.0.2 - Added conditional handling options for each of the three checks, completely configurable (See C:\ProgramData\chocolatey\extensions\chocolatey-preinstaller-checks\Chocolatey-Preinstaller-Checks.xml). Now compatible with Chocolatey Toast Notifications Extension. Get-chocoCounts replaced by Get-chocoInstanceCounts (Thanks by Michel Buczynski AKA MikeBoutch!) for Chocolatey Self Service Agent compatibility. Default 30 second pause changed to 5 seconds and cosmetically better display.
  • 0.0.1 - initial release

ROADMAP:

  • Option to abort install/uninstall if PendingRebootStatus is true.
  • Option to abort after a configurable amount of time waiting for other competing processes to finish.

Version History

Version Downloads Last updated Status
Chocolatey Preinstaller Checks Extension 0.0.2 470 Friday, November 23, 2018 exempted
Chocolatey Preinstaller Checks Extension 0.0.1 411 Thursday, July 19, 2018 exempted

Discussion for the Chocolatey Preinstaller Checks Extension Package

Ground rules:

  • This discussion is only about Chocolatey Preinstaller Checks Extension and the Chocolatey Preinstaller Checks Extension package. If you have feedback for Chocolatey, please contact the google group.
  • This discussion will carry over multiple versions. If you have a comment about a particular version, please note that in your comments.
  • The maintainers of this Chocolatey Package will be notified about new comments that are posted to this Disqus thread, however, it is NOT a guarantee that you will get a response. If you do not hear back from the maintainers after posting a message below, please follow up by using the link on the left side of this page or follow this link to contact maintainers. If you still hear nothing back, please follow the package triage process.
  • Tell us what you love about the package or Chocolatey Preinstaller Checks Extension, or tell us what needs improvement.
  • Share your experiences with the package, or extra configuration or gotchas that you've found.
  • If you use a url, the comment will be flagged for moderation until you've been whitelisted. Disqus moderated comments are approved on a weekly schedule if not sooner. It could take between 1-5 days for your comment to show up.

comments powered by Disqus
Chocolatey.org uses cookies to enhance the user experience of the site.
Ok