Mastodon

Managing Packages in Windows with Winget

Recently, a colleague told me about the new winget feature in Windows 10. This command line based package manager is developed by Microsoft as open source (CLI and repository) and offers the same features as, for example, apt-get in Ubuntu: software can be installed, updated and removed via command line.

Developers of applications can register their software in the “Windows Package Manager Community Repository” from where other developers can install them as “packages” using the CLI. Microsoft scans every package for malware which offers a basic security protection.

Benefits of a Package Manager

Of course, applications can be installed by downloading the installer and manually executing it. However, with a package manager, all applications are downloaded from one trusted source. That eliminates the danger of googling a malicious website and downloading malware instead of the intended tool. Also, this is the reason only trusted sources should be added to a package manager.

Another benefit of a package manager is that it can be used easily in scripts. For example, a software development team could assemble a list of applications usually used in the team to allow a quick onboarding of new team members. They only have to execute the script to set up their working environment. Yes, this could also be done with downloads from the tool’s websites. However, winget also supports downloading such lists. Doing this with winget is way easier than scripting everything by hand.

The last benefit I want to mention here is the centralized notification about updates. Yes, tools have their own ways to inform the user about new versions. However, having those in a central place is preferable and easier to manage.

Main Use Cases As Examples

Show current sources of packages:

winget source list

Update sources:

winget source update

Search a package in the sources:

winget search git

Show installed packages:

winget list

Filter list of installed packages:

winget list -q Discord

Show all installed packages with available upgrades:

winget upgrade

Upgrade specific package:

winget upgrade Discord

Upgrade all packages:

winget upgrade --all

Uninstall:

winget uninstall notepad++

Creating a Scheduled Task

Having all packages up to date is not only a good idea because of the potential new features of newer versions, it enhances security, too. With its task scheduler, Windows offers a way to run upgrades periodically like a batch job.

  1. Open the task scheduler with Windows key and search for “task scheduler”.
  2. Right-click on “Task Scheduler Library” and create a simple task.
  3. The program to start is C:\Users\your-user-id\AppData\Local\Microsoft\WindowsApps\winget.exe with the argument “upgrade –all”

Creating a Scheduled Task to Only Display Upgrades

Upgrading the packages automatically as shown above is the best way to stay up to date. However, if a package cannot be upgraded for some reason, the whole job stops and the packages after the canceled one will not be upgraded. There is an issue for this, but it’s still open for development.

On my working laptop, I don’t have the permissions to upgrade any Microsoft packages as they are managed by the admins in my company. Currently, winget cannot filter the packages to be updated, so I created a batch script to display all packages with upgrades. Using the Windows task scheduler, this script is my daily reminder to upgrade the applications manually.

Create a file named “winget-upgrade.bat” with the following content in some script- or tool folder:

@ECHO OFF
ECHO Executing winget upgrade ...
ECHO:
winget upgrade | findstr /r /v /c:"Microsoft"
ECHO:
ECHO Please upgrade the packages above manually with "winget upgrade ID-of-app".
ECHO:
ECHO (This scheduled task can be removed in the Windows Task Scheduler)
PAUSE

The line beginning with “winget” executes winget to show the list of packages with upgrades available. Using “findstr”, this list is filtered so it includes nothing with “Microsoft” in it.

Instead of creating a scheduled task which calls the winget.exe with the argument “upgrade –all”, enter the path to the batch file and no argument instead.

This will show something like:

Executing winget upgrade ...

Name                                         ID                                Version          Verfügbar        Quelle
-----------------------------------------------------------------------------------------------------------------------
Git                                          Git.Git                           2.31.0           2.35.0           winget
MongoDB Compass                              MongoDB.Compass.Full              1.21.2           1.30.1.0         winget
Mumble (client)                              Mumble.Mumble                     1.3.3            1.4.230          winget
Zoom                                         Zoom.Zoom                         5.9.2581         5.9.3169         winget
AWS SAM Command Line Interface               Amazon.SAM-CLI                    1.21.1           1.37.0           winget
Adobe Acrobat Reader DC                      Adobe.Acrobat.Reader.32-bit       21.007.20099     21.011.20039     winget
Node.js                                      OpenJS.NodeJS                     12.18.2          17.4.0           winget
AWS Command Line Interface                   Amazon.AWSCLI                     2.0.55.0         2.4.15.0         winget
8 Aktualisierungen verfügbar.

Please upgrade the packages above manually with "winget upgrade ID-of-app".

(This scheduled task can be removed in the Windows Task Scheduler)
Drücken Sie eine beliebige Taste . . .

Sources

Here are some (German) YouTube videos for the topic:

(Photo: https://pxhere.com/en/photo/1070638, CCO Public Domain