Powershell:msiexec/X从脚本调用时引发错误1619
我确实编写了一个脚本来从windows 7机器上卸载java:Powershell:msiexec/X从脚本调用时引发错误1619,powershell,cmd,uninstallation,windows-installer,Powershell,Cmd,Uninstallation,Windows Installer,我确实编写了一个脚本来从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文
[...]
$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出错了吗: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()
}
}
}
此外,启动流程参数-ArgumentList(示例中的别名:-arg)接受参数数组。传递单个字符串无法正常工作 试着这样做:
$Args = @( "/X", "$uninstall32", "/qn", "REMOVE=ALL", "/norestart" )
$p2=start-process "msiexec.exe" -argumentList $args -PassThru -wait -verb runAs
此外,如果“$Uninstall32”中的美元符号是安装程序的参数,则应在简单的引号之间写入:“$Uninstall32”请尝试以下方法:
$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()
这意味着特定的文件或包不可访问,也不适用于安装,如果您只使用powershell脚本作为测试路径只使用
test path
和运行脚本powershell-noexit“&“脚本路径”
powershell-noexit”和“脚本路径”,会话的参数,这样您就不必在机器范围内更改它,然后再将其更改回来。