[英]Powershell uninstall program with msiexec
我遇到了使msiexec用Powershell刪除Java的問題。 我將生成的命令輸出到屏幕上,並將其粘貼到批處理文件中,並且運行良好。 但是,當通過Powershell執行它時,它不會說“找不到包”。 誰能發現我可能做錯了什么? 我在谷歌上上下下,嘗試了幾種不同的方法來執行沒有成功且結果相同的命令。
cls
$java = Get-WmiObject -Class win32_product | where { $_.Name -like "*Java*"}
$msiexec = "c:\windows\system32\msiexec.exe";
#$msiexecargs = '/x:"$app.LocalPackage" /qr'
$msiexecargs = '/uninstall "$app.IdentifyingNumber" /qr /norestart'
if ($java -ne $null)
{
foreach ($app in $java)
{
write-host $app.LocalPackage
write-host $app.IdentifyingNumber
#&cmd /c "msiexec /uninstall $app.IdentifyingNumber /passive"
#Start-Process -FilePath $msiexec -Arg $msiexecargs -Wait -Passthru
[Diagnostics.Process]::Start($msiexec, $msiexecargs);
}
}
else { Write-Host "nothing to see here..." }
Write-Host "check end"
目標是使用Windows 7登錄腳本刪除最終用戶系統上所有Java版本,然后安裝最新版本。 我更喜歡全部使用Powershell,但如果無法正常工作,我將使用帶有卸載GUID硬編碼的批處理文件。
寫主機語句都是出於調試目的,我只是對以這種格式的某些變體執行msiexec感興趣:msiexec / x {GUID} / passive / norestart
我收到的錯誤是:“無法打開此安裝程序包。請確認該程序包存在並且可以訪問它,或者與應用程序供應商聯系以確認這是有效的Windows Installer程序包。”
我知道它是獨立運行的,只是不能在此腳本中運行...所以我認為這是語法問題。
如果您有任何問題,請通知我。
首先,您必須知道兩者之間的區別:
"$app.IdentifyingNumber"
和這個
"$($app.IdentifyingNumber)"
所以我認為您想使用后者(由於注釋行,代碼有些混亂):
&cmd /c "msiexec /uninstall $($app.IdentifyingNumber) /passive"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.