winget-install项目在Windows Server 2019上的安装与升级问题解析

winget-install项目在Windows Server 2019上的安装与升级问题解析

winget-install Install winget tool using PowerShell! Prerequisites automatically installed. Works on Windows 10/11 and Server 2022. winget-install 项目地址: https://gitcode.com/gh_mirrors/wi/winget-install

问题背景

在Windows Server 2019环境中,使用winget-install脚本安装或升级Microsoft.DesktopAppInstaller组件时,部分用户遇到了winget命令失效的问题。具体表现为:当从1.24.25200.0版本升级到1.25.340.0版本后,系统无法识别winget命令。

问题现象

用户在Windows Server 2019上执行以下操作流程时出现问题:

  1. 使用winget-install 5.0.5版本安装winget
  2. 通过winget update命令将Microsoft.DesktopAppInstaller从1.24.25200.0升级到1.25.340.0
  3. 升级完成后,系统提示"winget命令未识别"

技术分析

经过深入分析,该问题主要由以下两个因素导致:

  1. 权限问题:升级后的Microsoft.DesktopAppInstaller安装目录(C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.25.340.0_x64__8wekyb3d8bbwe)权限设置不当,导致管理员账户无法访问。

  2. 环境变量问题:系统PATH环境变量未自动更新,仍指向旧版本路径或缺少新版本的路径。

解决方案

临时解决方案

对于已经出现问题的系统,可以手动执行以下修复步骤:

  1. 设置目录权限
$FolderPath = "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.25.340.0_x64__8wekyb3d8bbwe"
$administratorsGroupSid = New-Object System.Security.Principal.SecurityIdentifier("S-1-5-32-544")
$administratorsGroup = $administratorsGroupSid.Translate([System.Security.Principal.NTAccount])
$acl = Get-Acl -Path $FolderPath
$accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule(
    $administratorsGroup,
    "FullControl",
    "ContainerInherit,ObjectInherit",
    "None",
    "Allow"
)
$acl.SetAccessRule($accessRule)
Set-Acl -Path $FolderPath -AclObject $acl
  1. 更新PATH环境变量: 手动将以下路径添加到系统PATH变量中:
C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.25.340.0_x64__8wekyb3d8bbwe

预防性解决方案

为避免此问题发生,建议在Windows Server 2019上:

  1. 先使用最新版winget-install脚本(5.0.7或更高版本)安装winget
  2. 然后再执行winget update命令

新版脚本已经包含了自动修复权限和环境变量的功能,可以有效预防此问题。

技术原理

该问题的根本原因在于Windows Server 2019对WindowsApps目录的特殊权限管理机制。与客户端Windows系统不同,Server版本默认对WindowsApps目录设置了更严格的访问控制。当winget升级后创建新版本目录时,系统不会自动继承原有的权限设置,导致管理员账户失去访问权限。

同时,由于Windows Server 2019的UWP应用管理机制,PATH环境变量不会自动更新指向新版本路径,导致系统无法找到winget可执行文件。

最佳实践建议

  1. 在Windows Server 2019上部署winget时,始终使用最新版本的winget-install脚本
  2. 在执行大规模部署前,先在测试环境验证winget升级流程
  3. 考虑将权限修复脚本纳入部署流程,作为预防措施
  4. 定期检查winget-install项目的更新,获取最新的兼容性修复

通过以上措施,可以确保winget在Windows Server 2019环境中的稳定运行,充分发挥其包管理功能。

winget-install Install winget tool using PowerShell! Prerequisites automatically installed. Works on Windows 10/11 and Server 2022. winget-install 项目地址: https://gitcode.com/gh_mirrors/wi/winget-install

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

苗轶锬Dalton

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值