逢年过节,如果你是那个肩负帮亲朋好友「看看电脑」工作的年轻人,多少都经历过「为什么你的电脑里又多了 N 个全家桶流氓软件」的时刻。但毕竟不是每个人都会使用正确的搜索引擎并分辨正确的下载渠道,对一切图个省事儿的小白来说,下载、更新 Windows 应用这件事轻则「安全下载」、重则「软件管家」,被「全家桶」乃至恶意应用趁虚而入是常有的事。

FcuubIjGMog4thxSUrIchkY1n1w
点了这个「安全下载」可就遭殃咯

但如果你的这位朋友正在使用搭载 Windows 11 电脑,事情就可以简单一点了。今天这篇文章就是为你提供一些新思路的。首先你应该一脸严肃地告诉这位朋友:

  1. 不要轻信某搜索引擎
  2. 不要轻信「安全下载」

必要时晓之以情、动之以理,此时这位朋友会告诉你:

那我也实在记不住这些官网链接,分不清靠谱的下载来源嘛。

于是你打开记事本,写下:

@echo off

rem Get the app name from the user.
set /p appname=输入你想安装或升级的应用名称:

rem Check if the app is installed.
rem If it is, upgrade it.
rem If it is not, install it.
rem If there are multiple app packages from different sources, set the winget source to only "winget".
rem This will ensure that the app is installed from the official Microsoft repository.

if exist "%appname%" (
winget upgrade "%appname%"
) else (
winget install "%appname%" --source winget
)

rem Display a success message.
echo %appname% 已成功安装/升级。

rem Keep the command line window open and let the user to exit with any key.

pause

然后顺手将这个记事本文件另存为「你喜欢的名字.bat」。注意,如果像上方实例一样在 set /p appname= 这里用了中文,保存时记得将编码设置为 ANSI 避免乱码。

W9A1b4WCZoisLKxivi4cJzj6nUg
想用中文留点骚话请注意编码设置

接下来你只需要把这个文件留在朋友或长辈的电脑上,想尽办法让他们不要删,并且让他们需要的时候双击运行一下即可。

Nq2sbacqeolrzYx8jK8cVFWpnbb
让我用心把你留下来

无论是新应用安装还是已安装应用升级,这个小文件均能搞定,用起来也颇有当年某些 Ghost 操作系统安装后清理小脚本的味道,如果你爸和我爸一个年纪,应该也会喜欢且信任这种脚本:

K6WlbYsnPo84zbxsN4HcwfUTn0f
以安装 Firefox 的安装为例
Br3QbsIM2oMAERx03qmcKhadnYc
以百度网盘的升级为例

明眼人已经看出来了,我们这里所使用的其实是 Windows 11 内置的包管理器 winget,并且在上面的脚本中,为了多个来源造成的版本选择问题,我们将应用安装来源指定为了 winget。所以如果你的亲友遇到了网络问题 winget 的版本无法完成任务,你也可以如法炮制制作一个应用安装来源指定为微软商店(msstore)的版本:

@echo off

rem Get the app name from the user.
set /p appname=输入你想安装或升级的应用名称:

rem Check if the app is installed.
rem If it is, upgrade it.
rem If it is not, install it.
rem If there are multiple app packages from different sources, set the winget source to only "msstore".
rem This will ensure that the app is installed from the Microsoft Store.

if exist "%appname%" (
winget upgrade "%appname%" --source msstore
) else (
winget install "%appname%" --source msstore
)

rem Display a success message.
echo %appname% 已成功安装/升级。

rem Keep the command line window open and let the user to exit with any key.

pause

Winget 这个工具在特定版本的 Windows 10 和所有 Windows 11 版本中早已内置,稍微熟悉一点命令行的朋友即可用它「一句话」搞定 Windows 应用的安装、升级、卸载……要是你的朋友有一定英语甚至命令行基础,最好的推荐方案还是让他好好读一下少数派的文章了解一下 winget。

关联阅读:这或许是 Windows 上最好的包管理工具:Windows Package Manager 1.0

但总体来说,包管理器作为一种简洁、直观、可靠的应用管理方式,对普通用户而言依然略有门槛。所以也有开发者基于 winget 做了具备 GUI 交互的小工具 WingetUI

LS6tbaU85o6r09xKYLacRS5lnDg
WingetUI 的 UI

Winget UI 同样基于 Windows 内置的 winget,并且还支持额外添加 ScoopChocolatey 作为来源。不过怎么说呢,你得说服亲友额外安装一个「管家」……而你刚刚才卸载了人家的 XX 管家啊!

> 下载 少数派 2.0 客户端、关注 少数派公众号,解锁全新阅读体验 📰

> 实用、好用的 正版软件,少数派为你呈现 🚀