【运维】微软官方包管理器winget的使用, 对比scoop/choco(含常用软件清单,本地镜像源自建,静默安装教程)

【运维】微软官方包管理器winget的使用, 对比scoop/choco(含常用软件清单,本地镜像源自建,静默安装教程)

文章目录

一、winget安装使用

1、winget介绍(对比scoop,choco)

WinGet(Windows Package Manager)是什么?

  • WinGet 是微软开发的 Windows 包管理器,它提供了一个命令行界面(CLI),允许用户自动化地安装、配置、更新和卸载 Windows 软件包。1
  • 这个工具旨在简化软件管理过程,使得开发者和系统管理员可以更高效地管理 Windows 系统上的软件。
  • 第三方包管理器(choco, scoop)的普及:随着第三方包管理器在Windows用户和开发者中的普及,显然有一个市场需求,希望微软能提供一个官方的、集成的解决方案。
shell 复制代码
PS C:\Users\aaa> winget
Windows 程序包管理器 v1.7.10582
版权所有 (C) Microsoft Corporation。保留所有权利。

WinGet 命令行实用工具可从命令行安装应用程序和其他程序包。

使用情况: winget  [<命令>] [<选项>]

下列命令有效:
  install    安装给定的程序包
  show       显示包的相关信息
  source     管理程序包的来源
  search     查找并显示程序包的基本信息
  list       显示已安装的程序包
  upgrade    显示并执行可用升级
  uninstall  卸载给定的程序包
  hash       哈希安装程序的帮助程序
  validate   验证清单文件
  settings   打开设置或设置管理员设置
  features   显示实验性功能的状态
  export     导出已安装程序包的列表
  import     安装文件中的所有程序包
  pin        管理包钉
  configure  将系统配置为所需状态
  download   从给定的程序包下载安装程序
  repair     修复所选包

如需特定命令的更多详细信息,请向其传递帮助参数。 [-?]

下列选项可用:
  -v,--version              显示工具的版本
  --info                    显示工具的常规信息
  -?,--help                 显示选定命令的帮助信息
  --wait                    提示用户在退出前按任意键
  --logs,--open-logs        打开默认日志位置
  --verbose,--verbose-logs  启用 WinGet 的详细日志记录
  --disable-interactivity   禁用交互式提示

可在此找到更多帮助: "https://aka.ms/winget-command-help"

scoop本地源仓库2软件清单

  • 参考以上第三方源仓库,选取其中之一并 fork 一个仓库。
  • 在 buckets 和 scripts 目录中维护自己定制的软件配置信息。
  • 确认在 github workflows 中,可以定时的基于 buckets 中的包配置的检测版本更新规则并更新。
  • 使用 scoop bucket add 命令添加到本地。
shell 复制代码
# 安装
iex "& {$(irm get.scoop.sh)} -RunAsAdmin"

# 管理
scoop bucket list
scoop bucket rm main
scoop bucket add scoop-cn https://xxx.com/xxx.git

choco本地镜像源仓库2

  • .nupkg 文件是 NuGet 包的一种文件格式,主要用于分发和管理可重复使用的代码,这种文件通常包含库、依赖项以及相关的元数据。NuGet 是一个包管理器,广泛应用于 .NET 开发生态系统中。
shell 复制代码
# 安装
Set-ExecutionPolicy RemoteSigned
iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex

# 指定源安装
choco source add -n=MyLocalChocoSource -s="http://<your-mac-ip>:8080/choco-packages"
choco install <package-name> -s "http://<your-mac-ip>:8080/choco-packages"

# nupkg
MyPackage
├── tools
│   ├── chocolateyInstall.ps1
│   └── myprogram.exe
└── mypackage.nuspec


# 创建 .nuspec 文件定义包的元数据
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>MyPackage</id>
    <version>1.0.0</version>
    <title>My Program</title>
    <authors>YourName</authors>
    <owners>YourName</owners>
    <description>This is a description of MyProgram.</description>
    <tags>example program</tags>
  </metadata>
</package>

# 创建chocolateyInstall.ps1,用于定义包的安装过程
$toolsDir   = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$packageDir = "$toolsDir\$(Split-Path -leaf $toolsDir)"
$installerPath = Join-Path $toolsDir 'myprogram.exe'
Start-Process -FilePath $installerPath -ArgumentList '/S' -Wait

# 使用 choco pack 命令将 .nuspec 文件和工具文件夹打包成 .nupkg 文件
choco pack

# 可以在本地安装此包来验证正确性:
choco install mypackage -s .

2、winget安装(win11自带,win10手动安装)

安装 WinGet for 低版本 Windows 10/11 及 Server 2022

  • 现有的一些低版本 Windows 10/11 和 Server 2022 都是不自带 WinGet 的 ,只有新版本的 11+ 及 Server 2025+ 会自带。引用1
  • 有时候需要在低版本 Windows 安装一些软件包,苦于没 WinGet,还是很不方便的。不过有第三方开发者 asheroto 给编写并提交了一份部署 WinGet 的 PS 脚本到 PowerShell Gallery 仓库,使用起来也极其方便。1, 2
  • 另外 WinGet 对 Windows 也是有版本要求的,可参考官方仓库的 ReadMe. 官方仓库, 微软官方文档
    》The client requires Windows 10 1809 (build 17763) or later at this time. Windows Server 2019 is not supported as the Microsoft Store is not available nor are updated dependencies. It may be possible to install on Windows Server 2022, this should be considered experimental (not supported) and requires dependencies to be manually installed as well.
shell 复制代码
# 安装部署脚本时,需要按提示接受部分协议文本或其它知情同意书
Install-Script -Name winget-install
winget-install

# 必要时可添加 -Force 参数,以便强制重新安装 winget
winget-install -Force

# 更新本地软件包缓存列表
winget source update

# 搜索及安装软件包
winget search "OpenSSH Beta"
winget install "OpenSSH Beta"

# 更多管理命令参考
winget --help

# 替换 USTC 镜像(不移除官方源的情况下,则添加到现有的列表内)
winget source remove winget
winget source add winget https://mirrors.ustc.edu.cn/winget-source

# 重置为官方地址
winget source reset winget

3、winget使用教程(常用软件安装指令,脚本批量执行)

winget使用教程1

Winget常用技巧

常用软件包安装指令

  • 如何使用 winget 包管理器:搜索、安装、导入导出和更换国内源等 1
  • 管理常用包, 1, 2
shell 复制代码
winget search 微信
winget install Tencent.WeChat

# 官方软件源,国内
winget install --id Huawei.HuaweiBrowser -e -s winget # 华为浏览器
winget install --id Google.Chrome -e -s winget        # 谷歌浏览器
winget install --id Tencent.QQ.NT -i -e -s winget     # QQ
winget install --id Tencent.WeChat -i -e -s winget    # 微信
winget install --id ByteDance.Feishu -e -s winget     # 飞书
winget install --id Youqu.ToDesk -e -s winget         # ToDesk远程桌面
winget install --id Alibaba.aDrive -e -s winget       # 阿里云盘
winget install --id Kingsoft.WPSOffice.CN -e -s winget   # WPS
winget install --id ByteDance.JianyingPro -e -s winget    # 剪映
winget install --id Kingsoft.KDocs -e -s winget       # 金山文档
winget install --id Bandisoft.Bandizip -v 6.29 -e -s winget   # Bandizip压缩软件
winget install --id Tencent.TencentMeeting -e -s winget   # 腾讯会议
winget install --id Logitech.OptionsPlus -e -s winget  # Logitech Options

# 官方软件源,国外
winget install --id Termius.Termius -e -s winget      # Termius
winget install --id Daum.PotPlayer -e -s winget       # PotPlayer播放器
winget install --id tailscale.tailscale -e -s winget  # Tailscale
winget install --id Eugeny.Tabby -e -s winget         # Tabby终端
winget install --id agalwood.Motrix -e -s winget      # Motrix下载器
winget install --id Microsoft.VisualStudioCode -e -s winget   # VSCode
winget install --id Microsoft.PowerToys -e -s winget  # PowerToys
winget install --id Git.Git -e -s winget                # Git
winget install --id Valve.Steam -e -s winget           #Steam

# 微软应用商店源
winget install --name 'DevToys' -e -s msstore          # DevToys
winget install --name 'Watt Toolkit' -e -s msstore     # Watt Toolkit

Windows重装后批量安装软件

shell 复制代码
@echo off

REM 检查是否存在软件列表文件
if not exist "software_list.txt" (
    echo Software list file does not exist! Please create the software list file and run the script again.
    exit /b
)

REM 逐行读取软件列表文件并安装软件
for /f "tokens=*" %%a in (software_list.txt) do (
    echo Installing software: %%a
    winget install %%a 
)

echo All software is already installed!
pause

二、Winget自建镜像源

1、使用本地临时文件安装(yaml)

本地安装清单文件:

shell 复制代码
# 这将使用本地 .yaml 文件安装软件包。
winget install --manifest MyPackage.yaml

# 如果安装过程中出现问题,可以查看 winget 的日志文件以获得更多信息。日志文件通常位于以下路径:
%LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\DiagOutputDir

# 创建清单文件:
wingetcreate new YourApp.exe
winget validate YourApp_Installer.yaml
winget install --manifest YourApp_Installer.yaml


Id: aaa.xxx
Name: aaa启动器
Publisher: aaa
Version: 1.1.4
License: Freeware
InstallerType: exe
Installers:
  - Architecture: x64
    InstallerUrl: https://example.com/Installer.exe
    InstallerSha256: <SHA256-Checksum-Here>

2、搭建本地软件包源(wingetcreate,manifests)

使用本地自定义软件包源,引用: 1

shell 复制代码
# winget默认使用微软官方的软件包源,但你也可以添加自己的源。比如,你可以搭建一个内部的软件包源以管理公司内部的软件分发。
winget source add --name <sourceName> --arg <sourceURL>

# 例如,添加一个名为CompanyRepo的内部源:
winget source add --name CompanyRepo --arg "https://company-internal-repo.com"

# 然后你就可以从这个源安装应用程序了:
winget install <AppName> --source CompanyRepo

# 在批量部署时,静默安装非常重要。winget支持通过命令行参数执行静默安装。比如:
winget install Microsoft.VisualStudioCode --silent --override "/S"


# 场景1:新员工入职自动化配置
在新员工入职时,管理员可以创建一个脚本,通过winget自动安装所有必需的开发工具、浏览器、压缩工具等,这样可以减少手动安装的时间并确保每个员工的工作环境一致。

# 场景2:安全性更新和补丁管理
管理员可以定期运行winget upgrade --all命令,确保所有应用程序都是最新的,减少因为使用旧版本软件带来的安全隐患。

# 场景3:定制化软件部署
如果公司内部有定制的软件,可以通过自建winget源,将这些软件打包并部署到所有需要的机器上。

创建本地自定义软件包源(winget-creat),1,

官方:1, 2, 3

shell 复制代码
# 安装 wingetcreate
winget install wingetcreate

# 启动 wingetcreate
wingetcreate new https://xxx.com/xxx.exe

# 配置 wingetcreate
# 然后一直选择默认值就可以。当然在最后选项中你的程序也可以添加到微软的库中。
正在下载和分析: https://www.daokeyuedu.com/docbox/%E7%A8%BB%E5%A3%B3%E9%98%85%E8%AF%BB%E5%99%A8%E5%AE%89%E8%A3%85%E7%A8%8B%E5%BA%8F.exe...
此工具将引导你完成一系列问题,以帮助你创建程序包清单。
有关每个字段限制的信息,请访问 https://aka.ms/winget-manifest-schema
按 ENTER 提交每个问题的值,包括接受 (默认) 值。
请为以下字段输入值:
程序包唯一标识符 |例如 Microsoft.VisualStudio|
 PackageIdentifier 值为: ZhikeOnline.DocBoxReaderInstaller
程序包版本 |例如 1.2.3.4|
 PackageVersion 值为: 2.12.36
程序包元数据默认区域设置 |例如 en-US|
 DefaultLocale 值为: en-US
安装程序所需的其他元数据来自 https://www.daokeyuedu.com/docbox/%E7%A8%BB%E5%A3%B3%E9%98%85%E8%AF%BB%E5%99%A8%E5%AE%89%E8%A3%85%E7%A8%8B%E5%BA%8F.exe
无提示安装程序开关
 Silent 值为: /s
无提示及进度安装程序开关
 SilentWithProgress 值为: /s
安装程序目标体系结构
 Architecture 值为: X86
发布者名 |例如 Microsoft|
 Publisher 值为: Zhike Online
程序包名 |例如 Visual Studio|
 PackageName 值为: DocBox Reader Installer
程序包许可证 |e.g. MIT License|
 License 值为: e.g. MIT License
简短程序包说明
 ShortDescription 值为: 稻壳阅读器 安装程序
 是否要修改可选的默认区域设置字段?: No
 是否要修改可选安装程序字段?: No
正在生成清单预览...
版本清单预览:
# Created using wingetcreate 1.2.5.0
# yaml-language-server: $schema=https://aka.ms/winget-manifest.version.1.4.0.schema.json
PackageIdentifier: ZhikeOnline.DocBoxReaderInstaller
PackageVersion: 2.12.36
DefaultLocale: en-US
ManifestType: version
ManifestVersion: 1.4.0
安装程序清单预览:
# Created using wingetcreate 1.2.5.0
# yaml-language-server: $schema=https://aka.ms/winget-manifest.installer.1.4.0.schema.json
PackageIdentifier: ZhikeOnline.DocBoxReaderInstaller
PackageVersion: 2.12.36
Installers:
- Architecture: x86
  InstallerType: exe
  InstallerUrl: https://www.daokeyuedu.com/docbox/%E7%A8%BB%E5%A3%B3%E9%98%85%E8%AF%BB%E5%99%A8%E5%AE%89%E8%A3%85%E7%A8%8B%E5%BA%8F.exe
  InstallerSha256: D42322ACAFEDB3BB68365FEC48848858ADD25E7D0627ACD0A8180F78A1ABEB2A
  InstallerSwitches:
    Silent: /s
    SilentWithProgress: /s
ManifestType: installer
ManifestVersion: 1.4.0
默认区域设置清单预览:
# Created using wingetcreate 1.2.5.0
# yaml-language-server: $schema=https://aka.ms/winget-manifest.defaultLocale.1.4.0.schema.json
PackageIdentifier: ZhikeOnline.DocBoxReaderInstaller
PackageVersion: 2.12.36
PackageLocale: en-US
Publisher: Zhike Online
PackageName: DocBox Reader Installer
License: e.g. MIT License
Copyright: Copyright 2016-2022 Beijing Zhike Online
ShortDescription: 稻壳阅读器 安装程序
ManifestType: defaultLocale
ManifestVersion: 1.4.0
清单验证成功: True
是否要对此清单进行更改?: No
清单已保存到 D:\manifests\z\ZhikeOnline\DocBoxReaderInstaller\2.12.36
是否要将清单提交到 Windows 程序包管理器存储库?: No

3、搭建本地镜像源(rewinged,https证书生成)

使用工具rewinged进行本地源的配置。因winget仅支持https的源所有首先进行证书生成然后启动https服务引用

shell 复制代码
# 开启https服务并且指定manifest路径
rewinged.exe  -https -listen localhost:8443 -manifestPath "C:\Users\Administrator\manifests"
rewinged.exe  -https -listen localhost:8443 -manifestPath "%USERPROFILE%\manifests"
./rewinged -https -listen localhost:8443

# 在winget中添加源
winget source add -n rewinged-local -a https://localhost:8443 -t "Microsoft.Rest"
winget source add -n rewinged-local -a https://localhost:8443/api -t "Microsoft.Rest"

# 安装本地源中的信息
winget install [software] -s rewinged-local

在 PowerShell 5.1 中生成并信任证书和私钥

shell 复制代码
# Because we are adding a certificate to the local machine store, this has to be run in an elevated PowerShell session

$IPs = [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() |
    Foreach-Object GetIPProperties |
    Foreach-Object UnicastAddresses |
    Foreach-Object Address |
    Foreach-Object {
        "&IPAddress=$( [System.Net.IPAddress]::new($_.GetAddressBytes() ))"
    }

[string]$SanIPs = -join $IPs

$SelfSignedCertificateParameters = @{
    'Subject'         = 'localhost'
    'TextExtension'   = @("2.5.29.17={text}DNS=localhost${SanIPs}")
    'NotAfter'        = (Get-Date).AddYears(1)
    'FriendlyName'    = 'rewinged HTTPS'
    'KeyAlgorithm'    = 'RSA'
    'KeyExportPolicy' = 'Exportable'
}
$cert = New-SelfSignedCertificate @SelfSignedCertificateParameters

$RSAPrivateKey    = [System.Security.Cryptography.X509Certificates.RSACertificateExtensions]::GetRSAPrivateKey($cert)
$PrivateKeyBytes  = $RSAPrivateKey.Key.Export([System.Security.Cryptography.CngKeyBlobFormat]::Pkcs8PrivateBlob)
$PrivateKeyBase64 = [System.Convert]::ToBase64String($PrivateKeyBytes, [System.Base64FormattingOptions]::InsertLineBreaks)

$CertificateBase64 = [System.Convert]::ToBase64String($cert.Export('Cert'), [System.Base64FormattingOptions]::InsertLineBreaks)

Set-Content -Path private.key -Encoding Ascii -Value @"
-----BEGIN RSA PRIVATE KEY-----`r`n${PrivateKeyBase64}`r`n-----END RSA PRIVATE KEY-----
"@

Set-Content -Path cert.pem -Encoding Ascii -Value @"
-----BEGIN CERTIFICATE-----`r`n${CertificateBase64}`r`n-----END CERTIFICATE-----
"@

$store = [System.Security.Cryptography.X509Certificates.X509Store]::new('Root', 'LocalMachine')
$store.Open('ReadWrite')
$store.Add($cert)
$store.Close()

Remove-Item $cert.PSPath

3、Windows静默安装

一般来说,不同的软件的封装类型都有固定的静默安装命令。

  • 查看软件的封装类型. 双击setup.exe,在弹出窗口的左上角单击,选择"About Setup"可查看软件的封装类型。然后根据其封装类型选择对应的静默安装命令。这个步骤可适用大部分的软件,不排除有些软件是比较特殊的。1
  • 使用工具如 7-Zip 或 WinRAR 解压安装文件,查看是否包含setup, installscript 之类的文件,有助于确定具体安装类型。
  • Microsoft Windows Installer
    如果某个软件是用 Windows Installer打包的,那你就应该能在文件夹中看到 *.msi 文件。这是最典型的特征,这些文件通常可以使用 /QB 和 /QN 参数进行自动安装。
    /qb 会在窗口中显示一个基本的安装进程。
    /qn 参数则不会显示任何窗口,直接在后台自动安装。
    为了阻止某些程序安装成功后自动重启动,你可以在 /qn 或者 /qb参数后使用REBOOT=Suppress标记。
    例如:安装虚拟光驱 DaemonTools:msiexec /i dtools.msi /qb REBOOT=SUPPRESS
  • InstallShield with MSI
    InstallShield with MSI 制作的安装文件,请使用类似:setup.exe /s /v" /qb 来安装。
  • WISE Installer
    用WISE技术打包的软件在安装的时候可以选择使用 /s 参数进行自动安装。
  • Inno Setup
    Inno Setup 制作的安装文件,请使用:setup.exe /sp- /silent /norestart
  • NullSoft Installation System
    使用 NSIS(NullSoft Installation System)制作的安装文件,可用 /S (注意大写)来进行静默安装("S"是大小写敏感的)。
    例如:Setup.exe /S
    也可以用 /D参数选择将要安装的目标分区和文件夹:
    例如:Setup.exe /S /D=E:\Software\QQ2007
  • Wise Installation Professional
    制作的安装文件,可用 /silent 参数进行静默安装。
  • WinRAR
    所有WinRAR做的自解压安装包可以使用 /s 参数进行静默安装

软件如果已经安装,到注册表中查询其安装/卸载参数

  • 看InstallSource(如果有)和UninstallString的参数内容信息 23

反正拿到一个安装程序,用/?查询下。

  • 如果不支持/?参数,还可以用各静默安装参数试试就知道了( [/S] [/silent [/noreboot]] [/verysilent [/sp-] [/norestart]] [/q] [/qn] [/qb] [REBOOT=SUPPRESS] [/s /v/qn] [/q:a /r:n] [/u /n /z] [/quiet[/SilentInstallNoSponsor] [/SilentInstall] [/s /qn] [/s /qd] [-s] [-q] 等)
    这步比较枯燥,但通常都比较有效。
  • 试完上面的参数,表面上看好像软件不支持静默安装,此时,可以考虑解压安装包:
    优先测试软件自带方法解压而支持静默安装:如:
    office 2003用/a参数解压;Office 2007 Service Pack补丁包用/extract解压;ACDSee10 /a解压
    不支持自带参数解压的用WinRAR或7-ZIP解压安装包,直接提取安装文件,执行静默安装
shell 复制代码
example_installer.exe /?
example_installer.exe -h
example_installer.exe --help
example_installer.exe /S
example_installer.exe /silent
example_installer.exe /quiet


1. .msi 格式
msiexec.exe /i ActiveSync.msi /quiet /norestart 
msiexec.exe /p hotfix.msp /quiet /norestart

2. 系统运行库
    ○ Visual C++ 2008 (VC8)解压出来得到msi文件 (官方下载的是exe文件,通过.exe /?查询也是/Q,但部署/Q和/q均报错,所以用解压部署的方法)
    ○ Visual C++ 2009(VC9).exe /q
    ○ Visual C++ 2010 (VC10).exe /q
    ○ Microsoft .NET Framework 1.1解压出来得到msi文件 (官方下载的是exe文件,通过.exe /?查询也是/Q,但部署/Q和/q均报错,所以用解压部署的方法)
    ○ Microsoft .NET Framework 2.0.exe /q
    ○ Microsoft .NET Framework 3.0.exe /q
    ○ Microsoft .NET Framework 3.5.exe /q
    ○ Microsoft .NET Framework 4.0.exe /q

3. 系统常用
    ○ Windows补丁,通常都是/quiet /norestart即可。如WindowsXP-KB915865-v11-x86-CHS.exe
    ○ WinRAR.exe /S
    ○ 7-ZIP.exe /S
    ○ Google拼音.exe /S
    ○ 搜狗拼音.exe /S
    ○ 驱动精灵2012.exe /S
    ○ CPU-Z v1.60 官方中文安装版.exe /S
    ○ Google Picasa v3.9.135.93 官方简体中文版.exe /S
    ○ 迅雷看看播放器 v4.8.8.966.exe /S
    ○ 网易有道桌面词典 5.0 正式版.exe /S
    ○ 微软雅黑字体for XP.exe /Q
    ○ VMware-workstation-full-8.0.2-591240.exe /silent /noSilentReboot
相关推荐
当归10241 小时前
nginx的反向代理和负载均衡
运维·nginx·负载均衡
日晨难再3 小时前
Linux:Bash中的文件描述符详解
linux·运维·服务器
tpoog3 小时前
[Linux]自定义shell详解
linux·运维·服务器·数据库·c++
无极9214 小时前
访问控制类型及部分具体介绍
运维·服务器·网络·安全·网络安全·模型·访问控制
MXsoft6184 小时前
美信监控易的优势:长期稳定运行
运维
ZHOUPUYU5 小时前
最新Kali Linux超详细安装教程(附镜像包)
linux·运维·服务器·开发语言·网络
RZer5 小时前
统信服务器操作系统【d版字符系统升级到dde图形化】配置方法
运维·服务器·统信uos
山兔15 小时前
服务器入侵追溯
运维·服务器
苹果醋35 小时前
Dubbo与SpringCloud的区别和优缺点
运维·nginx