【问题标题】:Powershell uninstall program with msiexec带有 msiexec 的 Powershell 卸载程序
【发布时间】:2012-06-13 03:03:43
【问题描述】:

我在让 msiexec 使用 Powershell 删除 java 时遇到了问题。我已将结果命令输出到屏幕并将其粘贴到批处理文件中,它运行良好。但是当它通过 Powershell 执行时,它会说“找不到包”。谁能发现我可能做错了什么?我在 google 上上下查找并尝试了几种不同的方式来执行命令,但没有成功,但结果相同。

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 包。”

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

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

【问题讨论】:

    标签: powershell java


    【解决方案1】:

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

    "$app.IdentifyingNumber"
    

    还有这个

    "$($app.IdentifyingNumber)"
    

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

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

    【讨论】:

    • 抱歉,我也想展示我在代码中尝试的其他内容。我在哪里可以获得有关您所做修改的更多信息?这工作得很好。谢谢!
    • 我认为blogs.msdn.com/b/powershell/archive/2006/07/15/… 是一个好的开始。如需更多信息,您需要一本书,例如 PowerShell in Action / PowerShell in Depth 等。
    猜你喜欢
    • 2015-03-30
    • 1970-01-01
    • 2018-07-18
    • 1970-01-01
    • 2011-12-17
    • 1970-01-01
    • 2011-09-15
    • 2012-05-02
    • 2018-08-11
    相关资源
    最近更新 更多