gpt4 book ai didi

使用 msiexec 卸载 Powershell 程序

转载 作者:行者123 更新时间:2023-12-01 05:16:56 25 4
gpt4 key购买 nike

我在使用 Powershell 获取 msiexec 删除 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 进行硬编码的批处理文件

write-host 语句都是为了调试的目的,我只是对以这种格式的某些变体执行 msiexec 感兴趣:msiexec/x {GUID}/passive/norestart

我得到的错误是:“无法打开此安装包。请验证该包是否存在并且您可以访问它,或者联系应用程序供应商以验证这是一个有效的 Windows Installer 包。”

我知道它可以单独工作,只是不在这个脚本中......所以我认为这是一个语法问题。

如果您有任何疑问,请告诉我。

最佳答案

首先你必须知道这之间的区别:

"$app.IdentifyingNumber"

还有这个

"$($app.IdentifyingNumber)"

所以我认为您想使用后者(由于注释行,代码有点困惑):

&cmd /c "msiexec /uninstall $($app.IdentifyingNumber) /passive"

关于使用 msiexec 卸载 Powershell 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11003012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com