Powershell:当脚本调用时,msiexec / X抛出错误1619

时间:2015-03-31 12:53:59

标签: powershell cmd uninstall msiexec

我写了一个脚本来从windows 7机器上卸载java:

[...]
$p2=start-process "msiexec.exe" -arg "/X $uninstall32 /qn REMOVE=ALL /norestart " -PassThru -wait -verb runAs
$p2.WaitForExit()
[...]

其中就像$uninstall32 = {26A24AE4-039D-4CA4-87B4-2F03217065FF}

如果我直接将这些ps1文件称为管理员,那么一切都很顺利。 按照更新过程的顺序,我必须从.bat文件调用我的(工作)ps1文件。这些是以这种方式调用我的ps1文件

if exist "%programfiles%\java\jre7" (

    powershell.exe -NoProfile -Command "Set-ExecutionPolicy Bypass"
    powershell.exe -NoProfile -file %~dp0uninstalljava7.ps1
    powershell.exe -NoProfile -Command "Set-ExecutionPolicy "restricted"
)

然后是erythin goin错误:msiexec抛出1619?

我不明白吗?!


解决:

对我而言,工作解决方案是:

Set-StrictMode -Version 2

$uninstall32key = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
$uninstall64key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"

$hklm32 = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, [Microsoft.Win32.RegistryView]::Registry32)
$hklm64 = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, [Microsoft.Win32.RegistryView]::Registry64)

$key32 = $hklm32.OpenSubKey($uninstall32key)
$key64 = $hklm64.OpenSubKey($uninstall64key)

$subkeys32 = $key32.GetSubKeyNames()
$subkeys64 = $key64.GetSubKeyNames()


foreach($subkey in $subkeys32)
{
    $key = $hklm32.OpenSubKey($uninstall32key+"\\"+$subkey)
    $displayName = $key.GetValue("DisplayName")

    if ($displayName -match "Java 7")
    {
        $uninstall32 =$key.GetValue("UninstallString") 
        if ($uninstall32) {
        $uninstall32 = $uninstall32 -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
        $params = @{
            "FilePath" = "$Env:SystemRoot\system32\msiexec.exe"
            "ArgumentList" = @(
                "/x"
                $uninstall32
                "/qn"
                "REMOVE=ALL"
                "/norestart"
            )
            "Verb" = "runas"
            "PassThru" = $true
            }
            $app1 = start-process @params
            $app1.WaitForExit()
        }
    }  
}

foreach($subkey in $subkeys64)
{
    $key = $hklm64.OpenSubKey($uninstall64key+"\\"+$subkey)
    $displayName = $key.GetValue("DisplayName")

    if ($displayName -match "Java 7")
    {
        $uninstall64 =$key.GetValue("UninstallString") 
        if ($uninstall64) {
        $uninstall64 = $uninstall64 -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
        $params = @{
            "FilePath" = "$Env:SystemRoot\system32\msiexec.exe"
            "ArgumentList" = @(
                "/x"
                $uninstall64
                "/qn"
                "REMOVE=ALL"
                "/norestart"
            )
            "Verb" = "runas"
            "PassThru" = $true
            }
            $app1 = start-process @params
            $app1.WaitForExit()
        }
    }  
} 

2 个答案:

答案 0 :(得分:1)

以这种方式尝试:

$appGUID = "{26A24AE4-039D-4CA4-87B4-2F03217065FF}"
$params = @{
  "FilePath" = "$Env:SystemRoot\system32\msiexec.exe"
  "ArgumentList" = @(
    "/x"
    $appGUID
    "/qn"
    "REMOVE=ALL"
    "/norestart"
  )
  "Verb" = "runas"
  "PassThru" = $true
}
$app = start-process @params
$app.WaitForExit()

答案 1 :(得分:0)

此外,start-process参数-ArgumentList(在您的示例中为Alias:-arg)接受参数的ARRAY。传递单个字符串无法正常工作。

试试这样:

$Args = @( "/X", "$uninstall32", "/qn", "REMOVE=ALL",  "/norestart" )
$p2=start-process "msiexec.exe" -argumentList $args -PassThru -wait -verb runAs

另外,如果美元符号在" $ Uninstall32"是安装程序的参数,您应该在简单的引号之间写下:' $ uninstall32'

相关问题