Downloads:

1,794

Downloads of v 0.0.2.1:

718

Last Update:

2/22/2019

Package Maintainer(s):

Software Author(s):

  • Bill Curran

Tags:

bcurran3 unofficial choco pre installer uninstaller checks extension

Chocolatey Preinstaller Checks Extension

0.0.2.1 | Updated: 2/22/2019

Downloads:

1,794

Downloads of v 0.0.2.1:

718

Maintainer(s):

Software Author(s):

  • Bill Curran

Chocolatey Preinstaller Checks Extension 0.0.2.1

All Checks are Passing

2 Passing Test


Validation Testing Passed


Verification Testing Passed

Details

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

>

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

>

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

>

NOTE: This applies to both open source and commercial editions of Chocolatey.

1. Ensure you are set for organizational deployment

Please see the organizational deployment guide

  • Open Source or Commercial:
    • Proxy Repository - Create a proxy nuget repository on Nexus, Artifactory Pro, or a proxy Chocolatey repository on ProGet. Point your upstream to https://chocolatey.org/api/v2. Packages cache on first access automatically. Make sure your choco clients are using your proxy repository as a source and NOT the default community repository. See source command for more information.
    • You can also just download the package and push it to a repository Download

3. Enter your internal repository url

(this should look similar to https://chocolatey.org/api/v2)

4. Choose your deployment method:


choco upgrade chocolatey-preinstaller-checks.extension -y --source="'STEP 3 URL'" [other options]

See options you can pass to upgrade.

See best practices for scripting.

Add this to a PowerShell script or use a Batch script with tools and in places where you are calling directly to Chocolatey. If you are integrating, keep in mind enhanced exit codes.

If you do use a PowerShell script, use the following to ensure bad exit codes are shown as failures:


choco upgrade chocolatey-preinstaller-checks.extension -y --source="'STEP 3 URL'" 
$exitCode = $LASTEXITCODE

Write-Verbose "Exit code was $exitCode"
$validExitCodes = @(0, 1605, 1614, 1641, 3010)
if ($validExitCodes -contains $exitCode) {
  Exit 0
}

Exit $exitCode

- name: Ensure chocolatey-preinstaller-checks.extension installed
  win_chocolatey:
    name: chocolatey-preinstaller-checks.extension
    state: present
    version: 0.0.2.1
    source: STEP 3 URL

See docs at https://docs.ansible.com/ansible/latest/modules/win_chocolatey_module.html.

Coming early 2020! Central Managment Reporting available now! More information...


chocolatey_package 'chocolatey-preinstaller-checks.extension' do
  action    :install
  version  '0.0.2.1'
  source   'STEP 3 URL'
end

See docs at https://docs.chef.io/resource_chocolatey_package.html.


Chocolatey::Ensure-Package
(
    Name: chocolatey-preinstaller-checks.extension,
    Version: 0.0.2.1,
    Source: STEP 3 URL
);

Requires Otter Chocolatey Extension. See docs at https://inedo.com/den/otter/chocolatey.


cChocoPackageInstaller chocolatey-preinstaller-checks.extension
{
   Name     = 'chocolatey-preinstaller-checks.extension'
   Ensure   = 'Present'
   Version  = '0.0.2.1'
   Source   = 'STEP 3 URL'
}

Requires cChoco DSC Resource. See docs at https://github.com/chocolatey/cChoco.


package { 'chocolatey-preinstaller-checks.extension':
  provider => 'chocolatey',
  ensure   => '0.0.2.1',
  source   => 'STEP 3 URL',
}

Requires Puppet Chocolatey Provider module. See docs at https://forge.puppet.com/puppetlabs/chocolatey.


salt '*' chocolatey.install chocolatey-preinstaller-checks.extension version="0.0.2.1" source="STEP 3 URL"

See docs at https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.chocolatey.html.

5. If applicable - Chocolatey configuration/installation

See infrastructure management matrix for Chocolatey configuration elements and examples.

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


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.



extensions\Chocolatey-Preinstaller-Checks.extension.psm1
# 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
<?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
# 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-chocoStatus.ps1
# 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 ""}
}

extensions\Get-PendingRebootStatus.ps1
# 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-WindowsInstallerStatus.ps1
# 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
# 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
# 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
   }
}

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.

Version Downloads Last Updated Status
Chocolatey Preinstaller Checks Extension 0.0.2 503 Friday, November 23, 2018 Exempted
Chocolatey Preinstaller Checks Extension 0.0.1 449 Thursday, July 19, 2018 Exempted

  • 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.

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