You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行PowerShell脚本时如何消除Windows Installer及权限请求弹窗?

解决PowerShell静默安装弹窗问题

问题核心原因

你的脚本存在两个关键问题:一是MSI/EXE安装包的静默参数使用错误,多余或不匹配的参数导致静默模式失效;二是脚本未获取管理员权限,触发UAC权限请求弹窗无法自动跳过。

修正方案

1. 规范静默安装参数

不同类型安装包需要对应正确的静默参数:

  • MSI包:通过msiexec.exe执行更可靠,标准静默参数为/quiet(完全无界面)或/passive(仅显示进度条),无需额外添加/i或/install。
  • EXE包:.NET系列安装包的标准静默参数为/quiet /norestart,避免弹出重启确认窗口。

2. 强制获取管理员权限

在脚本开头添加权限检测逻辑,若当前会话无管理员权限,自动重启脚本并获取权限,跳过UAC弹窗。

修正后的完整脚本

# 检测并获取管理员权限
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
    Start-Process PowerShell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
    exit
}

$softwarePath = "mypath"

# 安装ODBC 17和ODBC 18
Start-Process msiexec.exe -ArgumentList "/i `"$softwarePath\msodbcsql17.msi`" /quiet" -Wait
Write-Host "ODBC17 installed"
Start-Process msiexec.exe -ArgumentList "/i `"$softwarePath\msodbcsql18.msi`" /quiet" -Wait
Write-Host "ODBC18 installed"

# 安装Web Deploy v3.6
Start-Process msiexec.exe -ArgumentList "/i `"$softwarePath\WebDeploy_amd64_en-US.msi`" /quiet" -Wait
Write-Host "WebDeploy installed"

# 安装ASP.NET Core 7.0 Runtime (v7.0.5)
Start-Process "$softwarePath\dotnet-hosting-7.0.5-win.exe" -ArgumentList "/quiet /norestart" -Wait
Write-Host "dotnet-hosting-7.0.5 installed"

# 安装.NET 6.0 Desktop Runtime (v6.0.19)
Start-Process "$softwarePath\windowsdesktop-runtime-6.0.19-win-x64.exe" -ArgumentList "/quiet /norestart" -Wait
Write-Host "windowsdesktop-runtime-6.0.19 installed"

额外注意事项

  • 确保将$softwarePath替换为实际的安装文件路径,若路径包含空格需用引号包裹。
  • 若遇到特殊安装包,可通过执行[安装包路径]/?查看官方支持的静默参数。

内容的提问来源于stack exchange,提问作者Claire Wang

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.03 22:57:24