https://github.com/cli/cli 在其最新的 https://github.com/cli/cli/releases/tag/v2.10.1 中具有 Windows
的 MSI 安装程序。我一直在尝试安装的文件是 gh_2.10.1_windows_amd64.msi
。
目标是能够在多台计算机上远程安装该程序,这意味着静默和自主安装是必要的。
我曾尝试执行各种 Powershell
命令,例如以下
MsiExec.exe /i gh_2.10.1_windows_amd64.msi /qn /L*v "%WINDIR%\Temp\GitHubCLI-Install.log
或者
Start-Process msiexec.exe -Wait -ArgumentList '/i "C:\Users\myUser\Downloads\gh_2.10.1_windows_amd64.msi" /q /le "C:\Install.log"'
以及我从各种论坛和 Stackoverflow 帖子中尝试的许多其他各种排列和选项。
当我尝试静默安装它时,该命令执行并且似乎立即完成。但是,未安装 Github CLI
。
如果我运行类似:
msiexec /i C:\Users\myUser\Downloads\gh_2.10.1_windows_amd64.msi
出现一个设置 GUI,我需要单击它才能安装。
如何通过 Powershell
安装来远程部署和安装这个软件?
我意识到它也可以与 choco
、scoop
、winget
等一起安装。但是,不能保证每个系统都可以连接到这些服务。所以我需要打包 msi 并以这种方式在本地安装,以便 100% 确定安装在系统上完成。
编辑
它似乎正在运行 Powershell
,因为管理员允许安装安静地进行,无需任何输入。但这需要确认 UAC 提示。这对于远程更新是不可能的。我能做些什么?
从答案之一运行以下代码后:
# Check $LASTEXITCODE afterwards.
cmd /c 'MsiExec.exe /i gh_2.10.1_windows_amd64.msi /qn /L*v "%WINDIR%\Temp\GitHubCLI-Install.log'
安装发生并产生了日志。但是,发生了错误。以下是日志中产生错误的区域的片段:
Property(S): PrimaryVolumeSpaceAvailable = 0
Property(S): PrimaryVolumeSpaceRequired = 0
Property(S): PrimaryVolumeSpaceRemaining = 0
Property(S): INSTALLLEVEL = 1
Property(S): SOURCEDIR = C:\Users\myUser\Downloads\
Property(S): SourcedirProduct = {6E9B412F-42F0-4819-BDFF-3BFE1A28F531}
Property(S): ProductToBeRegistered = 1
MSI (s) (A4:DC) [12:45:54:500]: Note: 1: 1708
MSI (s) (A4:DC) [12:45:54:500]: Note: 1: 2205 2: 3: Error
MSI (s) (A4:DC) [12:45:54:500]: Note: 1: 2228 2: 3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 1708
MSI (s) (A4:DC) [12:45:54:500]: Note: 1: 2205 2: 3: Error
MSI (s) (A4:DC) [12:45:54:500]: Note: 1: 2228 2: 3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 1709
MSI (s) (A4:DC) [12:45:54:500]: Product: GitHub CLI -- Installation failed.
MSI (s) (A4:DC) [12:45:54:500]: Windows Installer installed the product. Product Name: GitHub CLI. Product Version: 2.10.1. Product Language: 1033. Manufacturer: GitHub, Inc.. Installation success or error status: 1603.
MSI (s) (A4:DC) [12:45:54:506]: Deferring clean up of packages/files, if any exist
MSI (s) (A4:DC) [12:45:54:506]: MainEngineThread is returning 1603
MSI (s) (A4:EC) [12:45:54:509]: RESTART MANAGER: Session closed.
MSI (s) (A4:EC) [12:45:54:509]: No System Restore sequence number for this installation.
=== Logging stopped: 2022-05-18 12:45:54 ===
MSI (s) (A4:EC) [12:45:54:512]: User policy value 'DisableRollback' is 0
MSI (s) (A4:EC) [12:45:54:512]: Machine policy value 'DisableRollback' is 0
MSI (s) (A4:EC) [12:45:54:512]: Incrementing counter to disable shutdown. Counter after increment: 0
MSI (s) (A4:EC) [12:45:54:512]: Note: 1: 1402 2: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\Rollback\Scripts 3: 2
MSI (s) (A4:EC) [12:45:54:513]: Note: 1: 1402 2: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer\Rollback\Scripts 3: 2
MSI (s) (A4:EC) [12:45:54:513]: Decrementing counter to disable shutdown. If counter >= 0, shutdown will be denied. Counter after decrement: -1
MSI (c) (88:D8) [12:45:54:515]: Decrementing counter to disable shutdown. If counter >= 0, shutdown will be denied. Counter after decrement: -1
MSI (c) (88:D8) [12:45:54:517]: MainEngineThread is returning 1603
=== Verbose logging stopped: 2022-05-18 12:45:54 ===
根据下面的一些评论,我尝试在不同的系统上运行上述命令,因为 1603 错误显然可能与某个文件夹有关。但是,在不同的系统上,它说我没有足够的权限。
MSI (s) (20:38) [16:48:34:696]: Note: 1: 2228 2: 3: Error 4: SELECT `Message` FROM `Error` WHERE `Error` = 1709
MSI (s) (20:38) [16:48:34:696]: Product: GitHub CLI -- Error 1925. You do not have sufficient privileges to complete this installation for all users of the machine. Log on as administrator and then retry this installation.
Error 1925. You do not have sufficient privileges to complete this installation for all users of the machine. Log on as administrator and then retry this installation.
回答1
正如您所说,安静(无人值守、无 UI)安装需要从提升的会话中运行。
在 PowerShell https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Remote 通过 https://docs.microsoft.com/powershell/module/microsoft.powershell.core/invoke-command
-ComputerName
的上下文中,远程会话自动且始终以提升方式运行 - 假设目标用户是远程计算机上BUILTIN\Administrators
组的成员。
因此,请尝试以下操作(假设当前用户是目标机器上的管理员):
Invoke-Command -Computer $computers -ScriptBlock {
# Use of cmd /c ensures *synchronous* execution
# (and also interprets %WINDIR% as intended).
cmd /c 'MsiExec.exe /i gh_2.10.1_windows_amd64.msi /qn /L*v "%WINDIR%\Temp\GitHubCLI-Install.log'
if ($LASTEXITCODE -ne 0) { throw "Installation failed with exit code $LASTEXITCODE." }
}
要在本地机器上运行安装程序 - 从提升的会话中 - 只需直接从上面的脚本块运行命令,即:
# Must run WITH ELEVATION.
# Check $LASTEXITCODE afterwards.
cmd /c 'MsiExec.exe /i gh_2.10.1_windows_amd64.msi /qn /L*v "%WINDIR%\Temp\GitHubCLI-Install.log'
回答2
或在 PS 5 中(作为管理员):
install-package gh_2.10.1_windows_amd64.msi
不幸的是,-additionalarguments 参数不起作用。