Downloads:
55,100
Downloads of v 0.0.2.2:
46,583
Last Update:
07 Apr 2022
Package Maintainer(s):
Software Author(s):
- Bill Curran
Tags:
bcurran3 unofficial choco pre installer uninstaller checks extensionChocolatey Preinstaller Checks Extension
- 1
- 2
- 3
0.0.2.2 | Updated: 07 Apr 2022
Downloads:
55,100
Downloads of v 0.0.2.2:
46,583
Maintainer(s):
Software Author(s):
- Bill Curran
Chocolatey Preinstaller Checks Extension 0.0.2.2
Legal Disclaimer: Neither this package nor Chocolatey Software, Inc. are affiliated with or endorsed by Bill Curran. The inclusion of Bill Curran trademark(s), if any, upon this webpage is solely to identify Bill Curran goods or services and not for commercial purposes.
- 1
- 2
- 3
Some Checks Have Failed or Are Not Yet Complete
Not All Tests Have Passed
Deployment Method: Individual Install, Upgrade, & Uninstall
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:
Deployment Method:
This applies to both open source and commercial editions of Chocolatey.
1. Enter Your Internal Repository Url
(this should look similar to https://community.chocolatey.org/api/v2/)
2. Setup Your Environment
1. Ensure you are set for organizational deployment
Please see the organizational deployment guide
2. Get the package into your environment
Option 1: Cached Package (Unreliable, Requires Internet - Same As Community)-
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://community.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
-
Open Source
-
Download the package:
Download - Follow manual internalization instructions
-
-
Package Internalizer (C4B)
-
Run: (additional options)
choco download chocolatey-preinstaller-checks.extension --internalize --source=https://community.chocolatey.org/api/v2/
-
For package and dependencies run:
choco push --source="'INTERNAL REPO URL'"
- Automate package internalization
-
Run: (additional options)
3. Copy Your Script
choco upgrade chocolatey-preinstaller-checks.extension -y --source="'INTERNAL REPO 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="'INTERNAL REPO URL'"
$exitCode = $LASTEXITCODE
Write-Verbose "Exit code was $exitCode"
$validExitCodes = @(0, 1605, 1614, 1641, 3010)
if ($validExitCodes -contains $exitCode) {
Exit 0
}
Exit $exitCode
- name: Install chocolatey-preinstaller-checks.extension
win_chocolatey:
name: chocolatey-preinstaller-checks.extension
version: '0.0.2.2'
source: INTERNAL REPO URL
state: present
See docs at https://docs.ansible.com/ansible/latest/modules/win_chocolatey_module.html.
chocolatey_package 'chocolatey-preinstaller-checks.extension' do
action :install
source 'INTERNAL REPO URL'
version '0.0.2.2'
end
See docs at https://docs.chef.io/resource_chocolatey_package.html.
cChocoPackageInstaller chocolatey-preinstaller-checks.extension
{
Name = "chocolatey-preinstaller-checks.extension"
Version = "0.0.2.2"
Source = "INTERNAL REPO URL"
}
Requires cChoco DSC Resource. See docs at https://github.com/chocolatey/cChoco.
package { 'chocolatey-preinstaller-checks.extension':
ensure => '0.0.2.2',
provider => 'chocolatey',
source => 'INTERNAL REPO URL',
}
Requires Puppet Chocolatey Provider module. See docs at https://forge.puppet.com/puppetlabs/chocolatey.
4. 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.
choco://chocolatey-preinstaller-checks.extension
To use choco:// protocol URLs, install (unofficial) choco:// Protocol support
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:
- https://github.com/chocolatey/choco/issues/544
- https://github.com/chocolatey/choco/issues/619
- https://github.com/chocolatey/choco/issues/761
- https://github.com/chocolatey/choco/issues/780
- https://github.com/chocolatey/choco/issues/1526
- https://github.com/chocolatey/choco/issues/1548
- https://github.com/chocolatey/choco/issues/1579
- and possibly others until such time that Chocolatey natively handles these issues better and this extension becomes moot. (Rumored to be 1.0.0 milestone)
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.
If you chocolatey-preinstaller-checks useful, please consider donating:
https://www.paypal.me/bcurran3donations or become a patron at https://www.patreon.com/bcurran3
# 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
<?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
-->
$ErrorActionPreference = 'Stop'
# 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
}
$ErrorActionPreference = 'Stop'
# 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 ""}
}
$ErrorActionPreference = 'Stop'
# 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
}
}
$ErrorActionPreference = 'Stop'
# 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 ""}
}
$ErrorActionPreference = 'Stop'
# 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
# }
#}
$ErrorActionPreference = 'Stop'
# 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
}
}
Log in or click on link to see number of positives.
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.
Add to Builder | Version | Downloads | Last Updated | Status |
---|---|---|---|---|
Chocolatey Preinstaller Checks Extension 0.0.2.2 | 46583 | Thursday, April 7, 2022 | Exempted | |
Chocolatey Preinstaller Checks Extension 0.0.2.1 | 6970 | Friday, February 22, 2019 | Exempted | |
Chocolatey Preinstaller Checks Extension 0.0.2 | 688 | Friday, November 23, 2018 | Exempted | |
Chocolatey Preinstaller Checks Extension 0.0.1 | 656 | Thursday, July 19, 2018 | Exempted |
Copyleft Bill Curran
- 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.3 Removed Chocolatey dependency as Chocoaltey v1.0 has been released and missed the 1.x milestone of becoming multi-instance aware and no new known goal.
- 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.
-
- powershell (≥ 3.0)
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.