【问题标题】:Unable to uninstall the x64 TargetPlatform msi using 32-bit PowerShell无法使用 32 位 PowerShell 卸载 x64 TargetPlatform msi
【发布时间】:2014-12-23 17:34:02
【问题描述】:

我有一个带有 TargetPlatform x64 位模式的 msi。我还在以 32 位模式运行的机器上安装了 PowerShell 2.0。我已经使用 powershell 脚本安装了 msi。现在,当我尝试使用下面提到的 powershell 脚本卸载 msi 时,出现错误:

找不到应用程序TestSetup

function Uninstall-MSI([string]$name)
{
    $success = $false

    # Read installation information from the registry
    $registryLocation = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\"
    foreach ($registryItem in $registryLocation)
    {
        # If we get a match on the application name
        if ((Get-itemproperty $registryItem.PSPath).DisplayName -eq $name)
        {
            # Get the product code if possible
            $productCode = (Get-itemproperty $registryItem.PSPath).ProductCode

            # If a product code is available, uninstall using it
            if ([string]::IsNullOrEmpty($productCode) -eq $false)
            {
                Write-Host "Uninstalling $name, ProductCode:$code"              
                $args="/uninstall $code"

                [diagnostics.process]::start("msiexec", $args).WaitForExit()                
                $success = $true
            }
            # If there is no product code, try to read the uninstall string
            else
            {
                $uninstallString = (Get-itemproperty $registryItem.PSPath).UninstallString

                if ([string]::IsNullOrEmpty($uninstallString) -eq $false)
                {
                    # Grab the product key and create an argument string
                    $match = [RegEx]::Match($uninstallString, "{.*?}")
                    $args = "/x $($match.Value) /qn"

                    [diagnostics.process]::start("msiexec", $args).WaitForExit()
                    Write-Host $uninstallString                 
                    $success = $true
                }
                else { throw "Unable to uninstall $name" }
            }           
        }
    }

    if ($success -eq $false)
    { throw "Unable to find application $name" }
}

Uninstall-MSI "TestSetup"

然后我将 MSI 更新为 x86 位模式并执行安装,然后尝试使用上述相同的 powershell 脚本进行卸载。它对我有用,没有任何问题。

谁能帮我解决上述问题?

【问题讨论】:

    标签: windows-installer powershell-2.0


    【解决方案1】:

    我进一步分析了这个问题,发现在我的机器上,Powershell 进程在 32 位模式下运行,而 msi 在 TargetPlatform x64 位模式下运行。在 32 位模式下运行的 Powershell 进程无法读取 64 位模式应用程序的注册表项。我在 Web 服务器上进行了相同的测试,Powershell 在 x64 位模式下运行,msi 在 TargetPlatform x64 位模式下运行,对我来说效果很好。

    【讨论】:

      猜你喜欢
      • 2021-11-16
      • 2018-06-30
      • 2015-03-07
      • 2012-08-08
      • 1970-01-01
      • 1970-01-01
      • 2010-11-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多