为了简化查找每个安装程序并手动启动它们的工作,我想制作一个 .bat 文件,为大约 10 个应用程序安装程序运行巧克力安装,同时无需执行任何操作。
我尝试使用
-command
选项输入命令,但它从未在 PowerShell 的提升窗口中执行它。
我想在提升的 PS shell 中运行的代码:
Set-ExecutionPolicy Bypass -scope Process -Force
Write-Host -ForegroundColor Black -BackgroundColor White "Chocolatey wird heruntergeladen und installiert"
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
choco feature enable -n=allowGlobalConfirmation
Write-Host -ForegroundColor Black -BackgroundColor White "Programme werden heruntergeladen und installiert"
choco install googlechrome
choco install firefox
choco install irfanview
choco install mpc-hc-clsid2
choco install 7zip
choco install notepadplusplus.install
choco install vlc
choco install adobereader
choco install libreoffice-still
理想情况下,我只需单击 .bat 文件并接受 PS 管理窗口的 UAC,所有程序都会在后台下载并安装。
powershell -Command "&{ Start-Process powershell -ArgumentList '-File C:\users\gabri\desktop\start.ps1' -Verb RunAs}"
.bat 文件仅显示 UAC,然后什么也没有发生。
将
Set-ExecutionPolicy Bypass -scope Process -Force
放入脚本文件 (*.ps1
) 在某种程度上达不到目的,因为如果持久配置的 执行策略 阻止脚本的执行,那么您对进程级覆盖的尝试将永远无法实现执行。
相反,请使用 PowerShell CLI 的
-ExecutionPolicy
参数对执行策略进行进程级覆盖。
此外,您可能需要使用
-NoExit
CLI 参数来保持提升的会话打开,以便您检查结果。
:: From a batch file.
powershell -Command "Start-Process -Verb RunAs powershell -ArgumentList '-ExecutionPolicy Bypass -NoExit -File C:\users\gabri\desktop\start.ps1'"