Installing Windows software with Chocolatey: a few notes
Posted by jpluimers on 2020/10/28
I will limit myself to software that needs Administrative elevation in order to be installed. This is the default use-case for Chocolatey. It is way way easier than installing software all by hand, but there are a few things you need to know, hence these notes.
Administrative elevation
Since the default use case is installing software that requires Administrative elevation during install, Chocolatey needs to run with Administrative privileges in order to perform these installs.
If you were hoping for a way around this (for instance by having a client/service architecture), then just stop here.
Even though such a structure could technically be created, getting it stable and working it correctly with a truckload of software to be installed (much of which not available as packages during Chocolatey development in the first place) is a task too big.
Think of the size of the Windows Installer team at Microsoft to get installers working in the first place, the extra effort needed by Chocolatey volunteers to get the installers working from the console, then another much more complex layer of getting them running from inside a service and communicating everything back and forth to a non-elevated command prompt would be a nightmare.
I won’t even mention the security steps involved to ensure the non-elevated command prompt has enough rights to send installation instructions to the elevated service.
So the first step is to have an elevated command prompt for Chocolatey.
Being elevated, and Chocolatey needing to download installers requires a local temporary place for them.
By default, that place is %Temp%\chocolatey
of the administrative user that elevated the Chocolatey command prompt.
This directory can grow quite big, so dir, so – since there is no choco cleanup
yet [WayBack] you need to either:
- install [WayBack] Chocolatey Gallery | (unofficial) Choco Cleaner (Script + Task) once, then every time you want to cleanup:
- wait for the default cleanup task to run on Sundays at 23:00 local time
- from an elevated console, run
%ChocolateyInstall%\lib\choco-cleaner\tools\choco-cleaner-manual.bat
- if you have a [WayBack] Chocolatey licensed edition, install [WayBack] FeaturesPackageReducer
- run
rd /s /q %Temp%\chocolatey%
every now and then (cleans less than the above methods).
Install Chocolatey itself
Either the direct one below, or the more secure one (so you can inspect the intermediate [WayBack] install.ps1
) at [WayBack] Installation using PowerShell from cmd.exe:
@echo off SET DIR=%~dp0% ::download install.ps1 %systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "((new-object net.webclient).DownloadFile('https://chocolatey.org/install.ps1','%DIR%install.ps1'))" ::run installer %systemroot%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& '%DIR%install.ps1' %*"
If you want to get rid of it, use [WayBack] Uninstallation.
Besides the one above and below, there are many more [WayBack] Installation: more install options
Output of direct install as Administrator (disclaimers apply):
C:\WINDOWS\system32>powershell -NoProfile -ExecutionPolicy Bypass -Command "[System.Net.WebRequest]::DefaultWebProxy.Credentials = [System.Net.CredentialCache]::DefaultCredentials; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH="%PATH%;%ALLUSERSPROFILE%\chocolatey\bin" Getting latest version of the Chocolatey package for download. Getting Chocolatey from https://chocolatey.org/api/v2/package/chocolatey/0.10.11. Downloading 7-Zip commandline tool prior to extraction. Extracting C:\Users\JEROEN~1\AppData\Local\Temp\chocolatey\chocInstall\chocolatey.zip to C:\Users\JEROEN~1\AppData\Local\Temp\chocolatey\chocInstall... Installing chocolatey on this machine Creating ChocolateyInstall as an environment variable (targeting 'Machine') Setting ChocolateyInstall to 'C:\ProgramData\chocolatey' WARNING: It's very likely you will need to close and reopen your shell before you can use choco. Restricting write permissions to Administrators We are setting up the Chocolatey package repository. The packages themselves go to 'C:\ProgramData\chocolatey\lib' (i.e. C:\ProgramData\chocolatey\lib\yourPackageName). A shim file for the command line goes to 'C:\ProgramData\chocolatey\bin' and points to an executable in 'C:\ProgramData\chocolatey\lib\yourPackageName'. Creating Chocolatey folders if they do not already exist. WARNING: You can safely ignore errors related to missing log files when upgrading from a version of Chocolatey less than 0.9.9. 'Batch file could not be found' is also safe to ignore. 'The system cannot find the file specified' - also safe. chocolatey.nupkg file not installed in lib. Attempting to locate it from bootstrapper. PATH environment variable does not have C:\ProgramData\chocolatey\bin in it. Adding... WARNING: Not setting tab completion: Profile file does not exist at 'C:\Users\jeroenAdministrator\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'. Chocolatey (choco.exe) is now ready. You can call choco from anywhere, command line or powershell by typing choco. Run choco /? for a list of functions. You may need to shut down and restart powershell and/or consoles first prior to using choco. Ensuring chocolatey commands are on the path Ensuring chocolatey.nupkg is in the lib folder
Installing packages
- For each package you want to install, run
choco install #packageName#
- If you want a quiet experience, add
--yes
to eachinstall command
- Optionally run
refreshenv
in each command-prompt to reflect any changes to the registry- it works from
cmd.exe
or batch file: [WayBack] choco/RefreshEnv.cmd at master · chocolatey/choco · GitHub - and as a PowerShell function: [WayBack] (GH-664) RefreshEnv Should also work in PowerShell · chocolatey/choco@7c84bb2 · GitHub
- it works from
Compressing
If you run out of SSD or VM disk space, you can try compress using compact /c /s *.*
in these directories:
C:\ProgramData\Package Cache
C:\ProgramData\Microsoft\VisualStudio\Packages
C:\ProgramData\Microsoft\ClickToRun\ProductReleases
Further reading
- [WayBack] How-To-Setup-Offline-Installation
- [WayBack] Implementing Chocolatey Self-Service for Non-Admin Users
- [WayBack] windows – Chocolatey as non-admin user – Super User
- Living on the edge with the beta [WayBack] installabsolutelatest.ps1
- [WayBack] Installation: Non Administrative Install
- [WayBack] Choco install doesn’t expand envvars, and installation into a custom location fails · Issue #748 · chocolatey/choco · GitHub
useRememberedArgumentsForUpgrades
: [WayBack] Chocolatey Gallery | Visual Studio Code 1.30.0 how to make/NoContextMenuFolders
permanent.
–jeroen
PS: always watch the output and logs!
In this case, I had to manually remove C:\ProgramData\chocolatey\lib-bkp\sysinternals
after closing procexp
(Process Explorer).
The easiest to do that is to run call %ChocolateyInstall%\lib\choco-cleaner\tools\choco-cleaner-manual.bat
after installing [WayBack] Chocolatey Gallery | (unofficial) Choco Cleaner (Script + Task).
I filed an issue about [WayBack] “You must be smarter than the average bear…” after upgrading to 7zip.install v18.6 and notepadplusplus.install v7.6.2 · Issue #1700 · chocolatey/choco · GitHub
C:\WINDOWS\system32>choco upgrade all Chocolatey v0.10.11 Upgrading the following packages: all By upgrading you accept licenses for the packages. 7zip v18.5.0.20180730 is the latest version available based on your source(s). You have 7zip.install v18.5.0.20180730 installed. Version 18.6 is available based on your source(s). Progress: Downloading 7zip.install 18.6... 100% Progress: Downloading 7zip 18.6... 100% 7zip v18.6 - Possibly broken 7zip package files upgrade completed. Performing other installation steps. The upgrade of 7zip was successful. Software install location not explicitly set, could be in package or default install location if installer. 7zip.install v18.6 [Approved] 7zip.install package files upgrade completed. Performing other installation steps. The package 7zip.install wants to run 'chocolateyInstall.ps1'. Note: If you don't run this script, the installation will fail. Note: To confirm automatically next time, use '-y' or consider: choco feature enable -n allowGlobalConfirmation Do you want to run the script?([Y]es/[N]o/[P]rint): y Installing 64 bit version Installing 7zip.install... 7zip.install has been installed. 7zip installed to 'C:\Program Files\7-Zip' Added C:\ProgramData\chocolatey\bin\7z.exe shim pointed to 'c:\program files\7-zip\7z.exe'. 7zip.install may be able to be automatically uninstalled. The upgrade of 7zip.install was successful. Software installed to 'C:\Program Files\7-Zip\' beyondcompare v4.2.8.23479 is the latest version available based on your source(s). choco-cleaner v0.0.5.1 is the latest version available based on your source(s). chocolatey v0.10.11 is the latest version available based on your source(s). chocolatey-core.extension v1.3.3 is the latest version available based on your source(s). DotNet4.6.1 v4.6.01055.20170308 is the latest version available based on your source(s). dotnet4.7.1 v4.7.2558.0 is the latest version available based on your source(s). You have Everything v1.4.1922 installed. Version 1.4.1924 is available based on your source(s). Progress: Downloading Everything 1.4.1924... 100% Everything v1.4.1924 [Approved] everything package files upgrade completed. Performing other installation steps. The package Everything wants to run 'chocolateyInstall.ps1'. Note: If you don't run this script, the installation will fail. Note: To confirm automatically next time, use '-y' or consider: choco feature enable -n allowGlobalConfirmation Do you want to run the script?([Y]es/[N]o/[P]rint): y Installing 64-bit Everything... Everything has been installed. Everything installed to 'C:\Program Files\Everything' Everything registered as Everything Post install command line: . 'C:\Program Files\Everything\Everything.exe' --disable-run-as-admin --install-service Starting Everything everything may be able to be automatically uninstalled. ShimGen has successfully created a shim for es.exe The upgrade of everything was successful. Software installed as 'exe', install location is likely default. Firefox v64.0 is the latest version available based on your source(s). git.install v2.20.1 is the latest version available based on your source(s). hg v4.6.1 is the latest version available based on your source(s). KB2919355 v1.0.20160915 is the latest version available based on your source(s). KB2919442 v1.0.20160915 is the latest version available based on your source(s). notepadplusplus v7.6.1 is the latest version available based on your source(s). You have notepadplusplus.install v7.6.1 installed. Version 7.6.2 is available based on your source(s). Progress: Downloading notepadplusplus.install 7.6.2... 100% Progress: Downloading notepadplusplus 7.6.2... 100% notepadplusplus v7.6.2 - Possibly broken notepadplusplus package files upgrade completed. Performing other installation steps. The package notepadplusplus wants to run 'chocolateyInstall.ps1'. Note: If you don't run this script, the installation will fail. Note: To confirm automatically next time, use '-y' or consider: choco feature enable -n allowGlobalConfirmation Do you want to run the script?([Y]es/[N]o/[P]rint): y The upgrade of notepadplusplus was successful. Software install location not explicitly set, could be in package or default install location if installer. notepadplusplus.install v7.6.2 [Approved] notepadplusplus.install package files upgrade completed. Performing other installation steps. The package notepadplusplus.install wants to run 'chocolateyInstall.ps1'. Note: If you don't run this script, the installation will fail. Note: To confirm automatically next time, use '-y' or consider: choco feature enable -n allowGlobalConfirmation Do you want to run the script?([Y]es/[N]o/[P]rint): y Installing 64-bit notepadplusplus.install... notepadplusplus.install has been installed. notepadplusplus.install installed to 'C:\Program Files\Notepad++' Added C:\ProgramData\chocolatey\bin\notepad++.exe shim pointed to 'c:\program files\notepad++\notepad++.exe'. notepadplusplus.install may be able to be automatically uninstalled. The upgrade of notepadplusplus.install was successful. Software installed as 'exe', install location is likely default. soapui v5.4.0 is the latest version available based on your source(s). SourceTree v3.0.8 is the latest version available based on your source(s). sql-server-management-studio v14.0.17289.1 is the latest version available based on your source(s). You have sysinternals v2018.12.14 installed. Version 2018.12.27 is available based on your source(s). Progress: Downloading sysinternals 2018.12.27... 100% sysinternals v2018.12.27 [Approved] sysinternals package files upgrade completed. Performing other installation steps. The package sysinternals wants to run 'chocolateyInstall.ps1'. Note: If you don't run this script, the installation will fail. Note: To confirm automatically next time, use '-y' or consider: choco feature enable -n allowGlobalConfirmation Do you want to run the script?([Y]es/[N]o/[P]rint): y Sysinternals Suite is going to be installed in 'C:\ProgramData\chocolatey\lib\sysinternals\tools' Downloading sysinternals from 'https://download.sysinternals.com/files/SysinternalsSuite.zip' Progress: 100% - Completed download of C:\Users\jeroenAdministrator\AppData\Local\Temp\chocolatey\sysinternals\2018.12.27\SysinternalsSuite.zip (23.23 MB). Download of SysinternalsSuite.zip (23.23 MB) completed. Hashes match. Extracting C:\Users\jeroenAdministrator\AppData\Local\Temp\chocolatey\sysinternals\2018.12.27\SysinternalsSuite.zip to C:\ProgramData\chocolatey\lib\sysinternals\tools... C:\ProgramData\chocolatey\lib\sysinternals\tools ShimGen has successfully created a shim for accesschk.exe ShimGen has successfully created a shim for accesschk64.exe ShimGen has successfully created a shim for AccessEnum.exe ShimGen has successfully created a shim for ADExplorer.exe ShimGen has successfully created a shim for ADInsight.exe ShimGen has successfully created a shim for adrestore.exe ShimGen has successfully created a shim for Autologon.exe ShimGen has successfully created a shim for Autoruns.exe ShimGen has successfully created a shim for Autoruns64.exe ShimGen has successfully created a shim for autorunsc.exe ShimGen has successfully created a shim for autorunsc64.exe ShimGen has successfully created a shim for Bginfo.exe ShimGen has successfully created a shim for Bginfo64.exe ShimGen has successfully created a shim for Cacheset.exe ShimGen has successfully created a shim for Clockres.exe ShimGen has successfully created a shim for Clockres64.exe ShimGen has successfully created a shim for Contig.exe ShimGen has successfully created a shim for Contig64.exe ShimGen has successfully created a shim for Coreinfo.exe ShimGen has successfully created a shim for ctrl2cap.exe ShimGen has successfully created a shim for Dbgview.exe ShimGen has successfully created a shim for Desktops.exe ShimGen has successfully created a shim for disk2vhd.exe ShimGen has successfully created a shim for diskext.exe ShimGen has successfully created a shim for diskext64.exe ShimGen has successfully created a shim for Diskmon.exe ShimGen has successfully created a shim for DiskView.exe ShimGen has successfully created a shim for du.exe ShimGen has successfully created a shim for du64.exe ShimGen has successfully created a shim for efsdump.exe ShimGen has successfully created a shim for FindLinks.exe ShimGen has successfully created a shim for FindLinks64.exe ShimGen has successfully created a shim for handle.exe ShimGen has successfully created a shim for handle64.exe ShimGen has successfully created a shim for hex2dec.exe ShimGen has successfully created a shim for hex2dec64.exe ShimGen has successfully created a shim for junction.exe ShimGen has successfully created a shim for junction64.exe ShimGen has successfully created a shim for ldmdump.exe ShimGen has successfully created a shim for Listdlls.exe ShimGen has successfully created a shim for Listdlls64.exe ShimGen has successfully created a shim for livekd.exe ShimGen has successfully created a shim for livekd64.exe ShimGen has successfully created a shim for LoadOrd.exe ShimGen has successfully created a shim for LoadOrd64.exe ShimGen has successfully created a shim for LoadOrdC.exe ShimGen has successfully created a shim for LoadOrdC64.exe ShimGen has successfully created a shim for logonsessions.exe ShimGen has successfully created a shim for logonsessions64.exe ShimGen has successfully created a shim for movefile.exe ShimGen has successfully created a shim for movefile64.exe ShimGen has successfully created a shim for notmyfault.exe ShimGen has successfully created a shim for notmyfault64.exe ShimGen has successfully created a shim for notmyfaultc.exe ShimGen has successfully created a shim for notmyfaultc64.exe ShimGen has successfully created a shim for ntfsinfo.exe ShimGen has successfully created a shim for ntfsinfo64.exe ShimGen has successfully created a shim for pagedfrg.exe ShimGen has successfully created a shim for pendmoves.exe ShimGen has successfully created a shim for pendmoves64.exe ShimGen has successfully created a shim for pipelist.exe ShimGen has successfully created a shim for pipelist64.exe ShimGen has successfully created a shim for portmon.exe ShimGen has successfully created a shim for procdump.exe ShimGen has successfully created a shim for procdump64.exe ShimGen has successfully created a shim for procexp.exe ShimGen has successfully created a shim for procexp64.exe ShimGen has successfully created a shim for Procmon.exe ShimGen has successfully created a shim for PsExec.exe ShimGen has successfully created a shim for PsExec64.exe ShimGen has successfully created a shim for psfile.exe ShimGen has successfully created a shim for psfile64.exe ShimGen has successfully created a shim for PsGetsid.exe ShimGen has successfully created a shim for PsGetsid64.exe ShimGen has successfully created a shim for PsInfo.exe ShimGen has successfully created a shim for PsInfo64.exe ShimGen has successfully created a shim for pskill.exe ShimGen has successfully created a shim for pskill64.exe ShimGen has successfully created a shim for pslist.exe ShimGen has successfully created a shim for pslist64.exe ShimGen has successfully created a shim for PsLoggedon.exe ShimGen has successfully created a shim for PsLoggedon64.exe ShimGen has successfully created a shim for psloglist.exe ShimGen has successfully created a shim for pspasswd.exe ShimGen has successfully created a shim for pspasswd64.exe ShimGen has successfully created a shim for psping.exe ShimGen has successfully created a shim for psping64.exe ShimGen has successfully created a shim for PsService.exe ShimGen has successfully created a shim for PsService64.exe ShimGen has successfully created a shim for psshutdown.exe ShimGen has successfully created a shim for pssuspend.exe ShimGen has successfully created a shim for pssuspend64.exe ShimGen has successfully created a shim for RAMMap.exe ShimGen has successfully created a shim for RegDelNull.exe ShimGen has successfully created a shim for RegDelNull64.exe ShimGen has successfully created a shim for regjump.exe ShimGen has successfully created a shim for ru.exe ShimGen has successfully created a shim for ru64.exe ShimGen has successfully created a shim for sdelete.exe ShimGen has successfully created a shim for sdelete64.exe ShimGen has successfully created a shim for ShareEnum.exe ShimGen has successfully created a shim for ShellRunas.exe ShimGen has successfully created a shim for sigcheck.exe ShimGen has successfully created a shim for sigcheck64.exe ShimGen has successfully created a shim for streams.exe ShimGen has successfully created a shim for streams64.exe ShimGen has successfully created a shim for strings.exe ShimGen has successfully created a shim for strings64.exe ShimGen has successfully created a shim for sync.exe ShimGen has successfully created a shim for sync64.exe ShimGen has successfully created a shim for Sysmon.exe ShimGen has successfully created a shim for Sysmon64.exe ShimGen has successfully created a shim for Tcpvcon.exe ShimGen has successfully created a shim for Tcpview.exe ShimGen has successfully created a shim for Testlimit.exe ShimGen has successfully created a shim for Testlimit64.exe ShimGen has successfully created a shim for vmmap.exe ShimGen has successfully created a shim for Volumeid.exe ShimGen has successfully created a shim for Volumeid64.exe ShimGen has successfully created a shim for whois.exe ShimGen has successfully created a shim for whois64.exe ShimGen has successfully created a shim for Winobj.exe ShimGen has successfully created a shim for ZoomIt.exe This is try 1/3. Retrying after 300 milliseconds. Error converted to warning: Toegang tot het pad procexp.exe is geweigerd. This is try 2/3. Retrying after 400 milliseconds. Error converted to warning: Toegang tot het pad procexp.exe is geweigerd. Maximum tries of 3 reached. Throwing error. Attempted to remove 'C:\ProgramData\chocolatey\lib-bkp\sysinternals' but had an error:: Toegang tot het pad procexp.exe is geweigerd. The upgrade of sysinternals was successful. Software installed to 'C:\ProgramData\chocolatey\lib\sysinternals\tools' Chocolatey upgraded 4/20 packages. See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log). Upgraded: - everything v1.4.1924 - notepadplusplus.install v7.6.2 - 7zip.install v18.6 - sysinternals v2018.12.27 C:\WINDOWS\system32>choco upgrade all Chocolatey v0.10.11 Upgrading the following packages: all By upgrading you accept licenses for the packages. 7zip v18.6 is newer than the most recent. You must be smarter than the average bear... 7zip.install v18.6 is the latest version available based on your source(s). beyondcompare v4.2.8.23479 is the latest version available based on your source(s). choco-cleaner v0.0.5.1 is the latest version available based on your source(s). chocolatey v0.10.11 is the latest version available based on your source(s). chocolatey-core.extension v1.3.3 is the latest version available based on your source(s). DotNet4.6.1 v4.6.01055.20170308 is the latest version available based on your source(s). dotnet4.7.1 v4.7.2558.0 is the latest version available based on your source(s). Everything v1.4.1924 is the latest version available based on your source(s). Firefox v64.0 is the latest version available based on your source(s). git.install v2.20.1 is the latest version available based on your source(s). hg v4.6.1 is the latest version available based on your source(s). KB2919355 v1.0.20160915 is the latest version available based on your source(s). KB2919442 v1.0.20160915 is the latest version available based on your source(s). notepadplusplus v7.6.2 is newer than the most recent. You must be smarter than the average bear... notepadplusplus.install v7.6.2 is the latest version available based on your source(s). soapui v5.4.0 is the latest version available based on your source(s). SourceTree v3.0.8 is the latest version available based on your source(s). sql-server-management-studio v14.0.17289.1 is the latest version available based on your source(s). sysinternals v2018.12.27 is the latest version available based on your source(s). Chocolatey upgraded 0/20 packages. See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
Leave a comment