-如果执行的 msi 安装程序最初请求许可,则等待和 -Passthru 将“被忽略”

问题描述 投票:0回答:1

我正在尝试制作一个脚本,用于检查 PC 是否已安装某个应用程序并安装了正确的版本(在我的例子中是 MySQL 8.0.32),如果没有安装,则执行预下载的 msi 文件来安装它存在。我已经有了检查部分,现在我正在执行安装程序部分。我目前得到了一个意外的结果,因为当我使用

Start-Process -FilePath <installer path> -Wait
调用安装程序时,似乎“允许此 msi 运行”对话框使
-Wait
无效,并使
PowerShell
认为安装过程已经结束。然后我找到了一个使用
-PassThru
的代码,但这似乎也不起作用。

这是我当前的代码:

$desiredGoVersion = "go1.20.4"
$desiredMySQLVersion = "8.0.32"

function Install-MySQL{
    $installerFileName = "mysql-installer-community-", $desiredMySQLVersion, ".0.msi" -Join ""
    $desiredMySQLInstallerPath = Join-Path $PSScriptRoot -ChildPath "installers" | Join-Path -ChildPath $installerFileName
    Write-Host $desiredMySQLInstallerPath

    if (Test-Path $desiredMySQLInstallerPath) {
        $proc = Start-Process -FilePath $desiredMySQLInstallerPath -Passthru

        do {start-sleep -Milliseconds 500}
        until ($proc.HasExited)

        Write-Host "MySQL installation process ended."
        Check-MySQL-Install
    } else {
        Write-Host "MySQL installer not found at specified path."
    }
}

function Check-MySQL-Install {
    $registryPath = "HKLM:\SOFTWARE\MySQL AB\MySQL Workbench 8.0 CE"
    $propertyName = "Version"

    $foundVersion = Get-ItemPropertyValue -Path $registryPath -Name $propertyName

    if ($foundVersion -eq $desiredMySQLVersion) {
        Write-Host "MySQL version $desiredMySQLVersion is already installed."
    } else {
        Install-MySQL
    }
}

我还尝试在管理模式下运行脚本

PowerShell
,但发生的情况是对话框没有显示。
-Wait
还是没等到什么。

更新:

我试过了

msiexec /a $installerFileName TRANSFORMS=transform.mst TARGETDIR=C:\Program Files\MySQL
并以光速结束。速度如此之快,我不得不强制关闭我的电脑,因为重试发生在几毫秒内,我无法从终端终止脚本。我也找到了
msiexec.exe /i "yarn-1.10.1.msi" INSTALLDIR="C:\programs" /qb
,但也不起作用。它们似乎都显示 Windows Installer 对话框显示了某人可以使用的标志,但我认为我使用了正确的标签

mysql powershell windows-installer
1个回答
1
投票

Start-Process -Wait
将等待子进程,但它不知道它的初始实例可能会生成新实例。在这种情况下,您必须寻找安装程序本身支持的等待参数,就像这个类似的问题一样:PowerShell Start-Process -Wait does not wait for VS Code

当您使用 MSI 时,您可以尝试显式使用

msiexec.exe
来调用您的 MSI 并添加静默安装参数,例如
/qn

如何使用自定义设置在无人值守的情况下安装MySQL?涵盖了无人值守的a. k. A。 MySQL 的静默安装相当好。

© www.soinside.com 2019 - 2024. All rights reserved.