当前位置: 首页 > 工具软件 > winget > 使用案例 >

windows_命令行软件包管理工具winget_基本使用案例(搜索软件并安装/检查已安装软件/更新软件/卸载软件)

狄晟睿
2023-12-01

winget 使用入门

命令说明
install安装指定的应用程序
show显示指定应用程序的详细信息。
source添加、删除和更新 winget 工具访问的 Windows 程序包管理器存储库。
search搜索某个应用程序。
list显示已安装的包。
升级升级给定的包。
uninstall卸载给定的包。
hash为安装程序生成 SHA256 哈希。
validate验证要提交到 Windows 程序包管理器存储库的清单文件。
设置打开设置。
功能显示试验功能的状态。
export导出已安装包的列表。
import将所有包安装到一个文件中。

创建别名

  • 可以将set-alias win winget的方式创建win作为winget的别名

获取帮助

PS C:\Users\cxxu> winget -?
Windows Package Manager v1.2.11601
Copyright (c) Microsoft Corporation. All rights reserved.

The winget command line utility enables installing applications and other packages from the command line.

usage: winget [<command>] [<options>]

The following commands are available:
  install    Installs the given package
  show       Shows information about a package
  source     Manage sources of packages
  search     Find and show basic info of packages
  list       Display installed packages
  upgrade    Upgrades the given package
  uninstall  Uninstalls the given package
  hash       Helper to hash installer files
  validate   Validates a manifest file
  settings   Open settings or set administrator settings
  features   Shows the status of experimental features
  export     Exports a list of the installed packages
  import     Installs all the packages in a file

For more details on a specific command, pass it the help argument. [-?]

The following options are available:
  -v,--version  Display the version of the tool
  --info        Display general info of the tool

获取子命令的帮助

  • For more details on a specific command, pass it the help argument. [-?]

  • 例如:

    • winget install -?
PS C:\Users\cxxu> win install -?
Windows Package Manager v1.2.11601
Copyright (c) Microsoft Corporation. All rights reserved.

Installs the selected package, either found by searching a configured source or directly from a manifest. By default, the query must case-insensitively match the id, name, or moniker of the package. Other fields can be used by passing their appropriate option.

usage: winget install [[-q] <query>] [<options>]

The following arguments are available:
  -q,--query                   The query used to search for a package

The following options are available:
  -m,--manifest                The path to the manifest of the package
  --id                         Filter results by id
  --name                       Filter results by name
  --moniker                    Filter results by moniker
  -v,--version                 Use the specified version; default is the latest version
  -s,--source                  Find package using the specified source
  --scope                      Select install scope (user or machine)
  -a,--architecture            Select the architecture to install
  -e,--exact                   Find package using exact match
  -i,--interactive             Request interactive installation; user input may be needed
  -h,--silent                  Request silent installation
  --locale                     Locale to use (BCP47 format)
  -o,--log                     Log location (if supported)
  --override                   Override arguments to be passed on to the installer
  -l,--location                Location to install to (if supported)
  --force                      Override the installer hash check
  --dependency-source          Find package dependencies using the specified source
  --accept-package-agreements  Accept all license agreements for packages
  --header                     Optional Windows-Package-Manager REST source HTTP header
  --accept-source-agreements   Accept all source agreements during source operations

More help can be found at: https://aka.ms/winget-command-install

常用子命令

搜索/查找软件

  • 使用帮助
PS C:\Users\cxxu> winget search -?
Windows Package Manager v1.2.11601
Copyright (c) Microsoft Corporation. All rights reserved.

Searches for packages from configured sources.

usage: winget search [[-q] <query>] [<options>]

The following arguments are available:
  -q,--query                  The query used to search for a package

The following options are available:
  --id                        Filter results by id
  --name                      Filter results by name
  --moniker                   Filter results by moniker
  --tag                       Filter results by tag
  --command                   Filter results by command
  -s,--source                 Find package using the specified source
  -n,--count                  Show no more than specified number of results (between 1 and 1000)
  -e,--exact                  Find package using exact match
  --header                    Optional Windows-Package-Manager REST source HTTP header
  --accept-source-agreements  Accept all source agreements during source operations
  • 实操

  • winget search mini

PS D:\repos\blogs> winget search mini
Name                   Id                     Version      Match                   Source
------------------------------------------------------------------------------------------
NWS-NOAA Weather Pred… 9WZDNCRDDD9P           Unknown                              msstore
Sago Mini Friends      9NBLGGH1ZK61           Unknown                              msstore
Mini Piano ®           9WZDNCRFJCN0           Unknown                              msstore
Mini Me Stage Free     9WZDNCRDPQHS           Unknown                              msstore
Mini Kids              9WZDNCRDQ0SZ           Unknown                              msstore

省略.....篇幅
Kubernetes - Minikube… Kubernetes.minikube    1.26.0                               winget
KeePass                DominikReichl.KeePass  2.51.1                               winget
MiniLyrics             Crintsoft.MiniLyrics   7.7.49                               winget
Miniforge3             CondaForge.Miniforge3  4.12.0-1                             winget
字节跳动开发者工具     ByteDance.BytedanceMi… 3.2.7-1                              winget
Miniconda3             Anaconda.Miniconda3    py39_4.10.3                          winget
小程序开发者工具       Alibaba.MiniProgramSt… 3.0.2                                winget
4t Tray Minimizer Free 4tNiagaraSoftware.4tT… 6.07                                 winget
Local Administrator P… Microsoft.LAPS         6.2.0.0                              winget
Weka                   UniversityOfWaikato.W… 3.9.6        Tag: data mining        winget
Orange                 UniversityofLjubljana… 3.31.1       Tag: data-mining        winget
微信开发者工具         Tencent.wechat-devtool 1.05.2108130 Tag: mini program       winget
WeChat                 Tencent.WeChat         3.7.0.30     Tag: Mini-Programs      winget

扫描/查看系统已安装的软件

列出所有软件


PS D:\repos\blogs> winget list
Name                      Id                         Version             Available Source
------------------------------------------------------------------------------------------
阿里云盘                  Alibaba.aDrive             3.3.0               3.6.0     winget
360ZipExtInstaller        360ZipExtInstaller_q2cs1j… 1.0.0.1011
360压缩                   360压缩                    4.0.0.1390
360安全卫士               360安全卫士                13.1.0.1005
PDF Reader - View, Edit,… 5E8FC25E.XODODOCS_3v3sf0k… 5.0.45.0
Intel® Graphics Command … AppUp.IntelGraphicsExperi… 1.100.3408.0
Clipchamp                 Clipchamp.Clipchamp_yxz26… 2.3.4.0
DTS Audio Processing      DTSInc.DTSAudioProcessing… 1.2.1.0
EasyConnect               EasyConnect                7,6,7,7
Intel® Hardware Accelera… HAXM                       7.6.5
Microsoft Office Home an… HomeStudent2019Retail - e… 16.0.15225.20288
Microsoft Office Home an… HomeStudent2019Retail - z… 16.0.15225.20288
SnipDo                    9NPZ2TVKJVT7               3.0.15.0                      msstore
Kali Linux                kalilinux.kalilinux        1.12.0.0                      winget
Microsoft Edge            Microsoft.Edge             103.0.1264.44                 winget
Microsoft Edge Dev        Microsoft.Edge.Dev         105.0.1300.0                  winget
Microsoft Edge Update     Microsoft Edge Update      1.3.163.19
Microsoft Edge WebView2 … Microsoft.EdgeWebView2Run… 103.0.1264.44                 winget
Cortana                   Microsoft.549981C3F5F10_8… 4.2204.13303.0
Microsoft News            Microsoft.BingNews_8wekyb… 1.0.6.0
MSN Weather               Microsoft.BingWeather_8we… 3.2.1.0
App Installer             Microsoft.DesktopAppInsta… 1.17.11601.0
Xbox                      Microsoft.GamingApp_8weky… 2105.900.24.0
Get Help                  Microsoft.GetHelp_8wekyb3… 10.2204.1222.0
Microsoft Tips            Microsoft.Getstarted_8wek… 10.2205.0.0
HEIF Image Extensions     Microsoft.HEIFImageExtens… 1.0.50272.0
English (United States) … Microsoft.LanguageExperie… 22000.8.13.0
中文(简体)本地体验包      Microsoft.LanguageExperie… 22000.22.83.0
Microsoft Edge Dev        Microsoft.MicrosoftEdge.D… 105.0.1300.0
Microsoft Edge            Microsoft.MicrosoftEdge.S… 103.0.1264.44
Office                    Microsoft.MicrosoftOffice… 18.2205.1091.0
Microsoft Solitaire Coll… Microsoft.MicrosoftSolita… 4.13.5310.0
Microsoft Sticky Notes    Microsoft.MicrosoftSticky… 4.0.4505.0
OneNote for Windows 10    Microsoft.Office.OneNote_… 16001.14326.20838.0

节约篇幅...省略中间..
Microsoft Store           Microsoft.WindowsStore_8w… 22204.1401.8.0
Windows Terminal Preview  Microsoft.WindowsTerminal… 1.14.1452.0                   winget
Windows Terminal          Microsoft.WindowsTerminal  1.13.11432.0                  winget
Windows Package Manager … Microsoft.Winget.Source_8… 2022.707.509.634
Xbox TCUI                 Microsoft.Xbox.TCUI_8weky… 1.24.10001.0
Xbox Game Bar Plugin      Microsoft.XboxGameOverlay… 1.54.4001.0
Xbox Game Bar             Microsoft.XboxGamingOverl… 5.722.5052.0
Xbox Identity Provider    Microsoft.XboxIdentityPro… 12.90.14001.0
Xbox Game Speech Window   Microsoft.XboxSpeechToTex… 1.21.13002.0
Phone Link                Microsoft.YourPhone_8weky… 1.22052.136.0
Windows Media Player      Microsoft.ZuneMusic_8weky… 11.2205.22.0

Movies & TV               Microsoft.ZuneVideo_8weky… 10.22041.10091.0

Microsoft Teams           MicrosoftTeams_8wekyb3d8b… 22168.200.1405.7434
Windows Web Experience P… MicrosoftWindows.Client.W… 421.20070.545.0
Mozilla Firefox (x64 en-… Mozilla Firefox 102.0 (x6… 102.0
Mozilla Maintenance Serv… MozillaMaintenanceService  97.0.1
NVIDIA Control Panel      NVIDIACorp.NVIDIAControlP… 8.1.962.0
PremiumSoft Navicat Prem… PremiumSoft.NavicatPremium 16.0.6                        winget
On Screen Display Utility OSD Utility                1.1.0.317
Oh My Posh                JanDeDobbeleer.OhMyPosh    7.81.1              8.13.1    winget
Microsoft OneDrive        Microsoft.OneDrive         22.121.0605.0002              winget
Realtek Audio Control     RealtekSemiconductorCorp.… 1.1.137.0
SangforVNC                SangforVNC                 7,1,0,2
搜狗输入法                Sogou.SogouInput           12.1.0.6042                   winget
JetBrains Toolbox         JetBrains.Toolbox          1.23.11731          1.24.120… winget...

列出指定软件(通配搜索)

  • 不带选项
  • 例如 winget list 天,列出相关软件
PS C:\Users\cxxu> winget list 天
Name           Id         Version     Source
---------------------------------------------
天翼云盘 6.4.2 天翼云盘   6.4.2
腾讯QQ         Tencent.QQ 9.6.2.28756 winget
  • 带选项--name
PS C:\Users\cxxu> winget list --name 腾讯
Name   Id         Version     Source
-------------------------------------
腾讯QQ Tencent.QQ 9.6.2.28756 winget
PS D:\repos\blogs> winget list --name visual
Name                        Id                          Version       Available     Source
------------------------------------------------------------------------------------------
Microsoft Visual Studio Co… Microsoft.VisualStudioCode  1.68.1                      winget
Microsoft Visual C++ 2015-… Microsoft.VC++2015-2022Red… 14.31.31103.0 14.32.31332.0 winget
Microsoft Visual C++ 2015-… Microsoft.VC++2015-2022Red… 14.31.31103.0 14.32.31332.0 winget
  • 卸载指定软件(包括其他不经过winget安装的软件一般也可以用winget卸载)

    • 例如 winget uninstall --name "movies & TV"
PS D:\repos\scripts> winget uninstall --name "movies & TV"
Found Movies & TV [Microsoft.ZuneVideo_8wekyb3d8bbwe]
Starting package uninstall...
  ██████████████████████████████  100%
Successfully uninstalled

实操

  • 搜索笔记软件siyuan

  • winget install siyuan -s msstore

    • 从windows 应用商店按照软件SiYuan笔记

检查软件更新

  • 使用list命令可以获取到可以更新的版本号(available字段)
winget list

更新软件(upgrade)(慎用)

注意,如果之前软件的安装路径不是默认的(譬如安装到了D盘),某些软件通过winget更新后,会安装到软件的默认位置(C盘)
这中情况下,会发生不符合预期的效果
重新检查软件列表,发现查到的软件版本仍然是旧版本的!

  • 如果您是安装默认的路径安装软件,那么可以使用winget upgrade 更新
PS D:\repos\blogs> winget upgrade -?
Windows Package Manager v1.2.11601
Copyright (c) Microsoft Corporation. All rights reserved.

Upgrades the selected package, either found by searching the installed packages list or directly from a manifest. By default, the query must case-insensitively match the id, name, or moniker of the package. Other fields can be used by passing their appropriate option.

usage: winget upgrade [[-q] <query>] [<options>]

The following arguments are available:
  -q,--query                   The query used to search for a package

The following options are available:
  -m,--manifest                The path to the manifest of the package
  --id                         Filter results by id
  --name                       Filter results by name
  --moniker                    Filter results by moniker
  -v,--version                 Use the specified version; default is the latest version
  -s,--source                  Find package using the specified source
  -e,--exact                   Find package using exact match
  -i,--interactive             Request interactive installation; user input may be needed
  -h,--silent                  Request silent installation
  -o,--log                     Log location (if supported)
  --override                   Override arguments to be passed on to the installer
  -l,--location                Location to install to (if supported)
  --force                      Override the installer hash check
  --accept-package-agreements  Accept all license agreements for packages
  --accept-source-agreements   Accept all source agreements during source operations
  --header                     Optional Windows-Package-Manager REST source HTTP header
  --all                        Update all installed packages to latest if available

More help can be found at: https://aka.ms/winget-command-upgrade
PS D:\repos\blogs> winget upgrade --all
Found 阿里云盘 [Alibaba.aDrive] Version 3.6.0
Found Microsoft Edge WebView2 Runtime [Microsoft.EdgeWebView2Runtime] Version 103.0.1264.49
Found Oh My Posh [JanDeDobbeleer.OhMyPosh] Version 8.13.1
Found JetBrains Toolbox [JetBrains.Toolbox] Version 1.25.12424
Found Python 3 [Python.Python.3] Version 3.10.5150.0
Found Microsoft Visual C++ 2015-2022 Redistributable (x64) [Microsoft.VC++2015-2022Redist-x64] Version 14.32.31332.0
Found Microsoft Visual C++ 2015-2022 Redistributable (x86) [Microsoft.VC++2015-2022Redist-x86] Version 14.32.31332.0
Found 网易有道词典 [Youdao.YoudaoDict] Version 9.0.1.1
(1/8) Found 阿里云盘 [Alibaba.aDrive] Version 3.6.0
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Downloading https://tongyongxiezuo.oss-cn-zhangjiakou.aliyuncs.com/desktop/aDrive-desktop/3.6.0/update/win32/ia32/aDrive-3.6.0.exe
  ██████████████████████████████  92.5 MB / 92.5 MB
Successfully verified installer hash
Starting package install...
Successfully installed

(2/8) Found Microsoft Edge WebView2 Runtime [Microsoft.EdgeWebView2Runtime] Version 103.0.1264.49
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Downloading https://msedge.sf.dl.delivery.mp.microsoft.com/filestreamingservice/files/b123748a-b671-44cf-9dcd-ced6bf841bff/MicrosoftEdgeWebView2RuntimeInstallerX64.exe
  ██████████████████████████████   124 MB /  124 MB
Successfully verified installer hash
Starting package install...
Installer failed with exit code: 2147747880

(3/8) Found Oh My Posh [JanDeDobbeleer.OhMyPosh] Version 8.13.1
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Downloading https://github.com/JanDeDobbeleer/oh-my-posh/releases/download/v8.13.1/install-amd64.exe
  ██████████████████████████████  6.55 MB / 6.55 MB
Successfully verified installer hash
Starting package install...
Successfully installed

(4/8) Found JetBrains Toolbox [JetBrains.Toolbox] Version 1.25.12424
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Downloading https://download-cdn.jetbrains.com/toolbox/jetbrains-toolbox-1.25.12424.exe
  ██████████████████████████████  57.9 MB / 57.9 MB
Successfully verified installer hash
Starting package install...
Successfully installed

(5/8) Found Python 3 [Python.Python.3] Version 3.10.5150.0
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Downloading https://www.python.org/ftp/python/3.10.5/python-3.10.5-amd64.exe
  ██████████████████████████████  27.3 MB / 27.3 MB
Successfully verified installer hash
Starting package install...
Successfully installed

卸载软件

卸载qq

  • winget uninstall --moniker qq
PS D:\repos\blogs> winget uninstall --moniker qq
Found 腾讯QQ [Tencent.QQ]
Starting package uninstall...

卸载edge dev版

PS C:\Users\cxxu> win uninstall "microsoft edge dev"
Multiple installed packages found matching input criteria. Please refine the input.
Name               Id
------------------------------------------------------------
Microsoft Edge Dev Microsoft.Edge.Dev
Microsoft Edge Dev Microsoft.MicrosoftEdge.Dev_8wekyb3d8bbwe
PS C:\Users\cxxu> win uninstall  Microsoft.Edge.Dev
Found Microsoft Edge Dev [Microsoft.Edge.Dev]
Starting package uninstall...
Uninstall failed with exit code: 19
PS C:\Users\cxxu> win uninstall  Microsoft.Edge.Dev

检查卸载情况

PS C:\Users\cxxu> win list --name edge
Name                            Id                                           Version       Available     Source
---------------------------------------------------------------------------------------------------------------
Microsoft Edge                  Microsoft.Edge                               103.0.1264.44 103.0.1264.49 winget
Microsoft Edge Update           Microsoft Edge Update                        1.3.163.19
Microsoft Edge WebView2 Runtime Microsoft.EdgeWebView2Runtime                103.0.1264.44 103.0.1264.49 winget
Microsoft Edge                  Microsoft.MicrosoftEdge.Stable_8wekyb3d8bbwe 103.0.1264.44

发现edge dev卸载完毕

more refs(来自篇相对完善的winget使用教程)

ow to Use WINGET on Windows 11

 类似资料: