[英]Powershell: msiexec /X throws error 1619 when call from script
我确实编写了一个脚本从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()
}
}
}
尝试这种方式:
$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()
另外,启动过程参数-ArgumentList(在您的示例中为Alias:-arg)接受参数的ARRAY。 传递单个字符串不能正常工作。
尝试这样:
$Args = @( "/X", "$uninstall32", "/qn", "REMOVE=ALL", "/norestart" )
$p2=start-process "msiexec.exe" -argumentList $args -PassThru -wait -verb runAs
另外,如果“ $ Uninstall32”中的美元符号是安装程序的参数,则应在简单引号之间写上它:'$ uninstall32'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.