Featured image of post Quick Dive: Managing Applications With Winget

Quick Dive: Managing Applications With Winget

Happy Saturday! Welcome back to another blog post. In this edition, we’ll be taking a short break from OneDrive to have a quick dive into managing applications using the command line tool winget - Microsoft’s “Client Interface to the Windows Package Manager service”.

If you’re looking for another way to install, update, and uninstall software on Windows, you’re in the right place. Let’s get started!

Checking if Winget is Installed

Winget is supported on Windows 10 1709 (build 16299) or later. Before we jump in, let’s make sure it’s installed in your environment. You can easily check by opening your command prompt or PowerShell and typing the following:

1
winget --help

or

1
winget -?

If Winget is installed, you’ll see a helpful command summary along with various options and commands that you can use.

An important note from Microsoft on this: The winget tool will not be available until you have logged into Windows as a user for the first time, triggering Microsoft Store to register Windows Package Manager as part of an asynchronous process. If you have recently logged in as a user for the first time and find that winget is not yet available, you can open PowerShell and enter the following command to request this winget registration: Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe

Installing the Latest Version of Winget

If you’re missing Winget or want to ensure you have the latest version, you can install it using the following command from Microsoft:

1
2
3
4
5
6
7
8
$progressPreference = 'silentlyContinue'
Write-Information "Downloading WinGet and its dependencies..."
Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle
Invoke-WebRequest -Uri https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx -OutFile Microsoft.VCLibs.x64.14.00.Desktop.appx
Invoke-WebRequest -Uri https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.7.3/Microsoft.UI.Xaml.2.7.x64.appx -OutFile Microsoft.UI.Xaml.2.7.x64.appx
Add-AppxPackage Microsoft.VCLibs.x64.14.00.Desktop.appx
Add-AppxPackage Microsoft.UI.Xaml.2.7.x64.appx
Add-AppxPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle

You could also install “App Installer” through the Microsoft Store to get to the same outcome.

Winget offers an array of powerful command-line options that enable you to perform various tasks. To explore them in detail, you can use the following command:

1
winget -?

This will provide you with a handy list of commands, Each with their own context relevant options:

Winget Help Output - Available Commands

To get more details on any specific commands available options, pass them the help argument. [-?]

for example, winget install -? would return the relevant options realating to installation. Some of these that are going to be relevant to us shortly are:

Install OptionDescription
–idFilter results by id
–nameFilter results by name
-h,–silentRequest silent installation
–accept-package-agreementsAccept all licenseagreements for packages
–disable-interactivityDisable interactive prompts

Searching for Packages

Finding packages with Winget is simple. If you’re looking for, let’s say, Google Chrome, you can use the following command:

1
winget search Chrome

This will present you with a list of matching packages, along with their IDs, versions, and sources.

Getting Package Information

Curious about the details of a specific package? You can use the show command to retrieve comprehensive information. For instance, to get details about Google Chrome, you can use:

1
winget show --id Google.Chrome

It’s a good idea to use the ‘Show’ command to verify the package you are interacting with, is what you think it is.

Silently Installing a Package

Sometimes you might want to install packages without any prompts. To do so, use the --silent flag. For example:

1
winget install --id Google.Chrome --silent

Silently Upgrading All Packages

To keep your applications up to date without manual intervention, use the upgrade command with the following options:

1
winget upgrade --all --uninstall-previous --force --accept-package-agreements --accept-source-agreements --silent --disable-interactivity

Scripting winget

Microsoft provides an Example Bash script that can install packages one after another using Winget.

1
2
3
4
5
6
7
8
@echo off  
Echo Install Powertoys and Terminal  
REM Powertoys  
winget install Microsoft.Powertoys  
if %ERRORLEVEL% EQU 0 Echo Powertoys installed successfully.  
REM Terminal  
winget install Microsoft.WindowsTerminal  
if %ERRORLEVEL% EQU 0 Echo Terminal installed successfully.   %ERRORLEVEL%

An important note from Microsoft on this: When scripted, winget will launch the applications in the specified order. When an installer returns success or failure, winget will launch the next installer. If an installer launches another process, it is possible that it will return to winget prematurely. This will cause winget to install the next installer before the previous installer has completed.

Silently Installing Multiple Specific Packages (One Liner)

If you want to automate the installation of a specific set of packages, you can use a script like this:

1
winget install --id "7zip.7zip" "Adobe.Acrobat.Reader.64-bit" "Zoom.Zoom" "Notepad++.Notepad++" "Google.Chrome" "Mozilla.Firefox" "VideoLAN.VLC" "Egnyte.EgnyteDesktopApp" --silent --disable-interactivity --accept-source-agreements --accept-package-agreements

Listing Installed Packages

You can get a list of installed packages using the command:

1
winget list

This command will output a table of installed packages and properties such as Name, Id, Version & Available Source.

Interestingly, this command will even display packages that were not originally installed through Windows Package Manager.

Silently Uninstalling a Package

Removing packages silently is just as easy. For example, to silently uninstall Google Chrome:

1
winget uninstall --id Google.Chrome --silent

With these Winget commands and techniques, you have the power to manage your applications using Microsofts own package manager.

That’s it for today! I hope this quick dive into managing applications with Winget proves helpful. Until next time, happy coding and exploring! 🚀

Automate and script away - Happy Shellcode Saturday!

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy