代码之家  ›  专栏  ›  技术社区  ›  David Pee

通过PowerShell卸载应用程序

  •  0
  • David Pee  · 技术社区  · 7 年前

    我已经为此工作了几天,无论我如何运行和使用它,它似乎都会通过PowerShell卸载程序并返回成功代码:

    __GENUS          : 2
    __CLASS          : __PARAMETERS
    __SUPERCLASS     :
    __DYNASTY        : __PARAMETERS
    __RELPATH        :
    __PROPERTY_COUNT : 1
    __DERIVATION     : {}
    __SERVER         :
    __NAMESPACE      :
    __PATH           :
    ReturnValue      : 0
    PSComputerName   :
    

    这种情况发生在各种众所周知的难以删除的软件上,如McAfee。

    使用的命令是:

     Get-WmiObject -Class win32_product -Filter "Name like '%McAfee%'" | ForEach-Object {$_.Uninstall()}
    

    我在这里尝试了各种脚本、解决方案以及它们的变体(如下面)。

    $uninstall32 = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "Yahoo Messenger" } | select UninstallString
    
    $uninstall64 = gci "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match "Yahoo Messenger" } | select UninstallString
    
    if ($uninstall64) {
        $uninstall64 = $uninstall64.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
        $uninstall64 = $uninstall64.Trim()
        Write "Uninstalling (x64)..."
        start-process "msiexec.exe" -arg "/X $uninstall64 /qb" -Wait
        }
    if ($uninstall32) {
        $uninstall32 = $uninstall32.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
        $uninstall32 = $uninstall32.Trim()
        Write "Uninstalling (x32)..."
        start-process "msiexec.exe" -arg "/X $uninstall32 /qb" -Wait}
    

    即使是像Yahoo Messenger这样简单的命令,当以管理员身份从Powershell窗口运行时,该命令也无法卸载应用程序,但返回成功代码和/或WMI应用程序列表中不再存在。

    1 回复  |  直到 7 年前
        1
  •  1
  •   veefu    7 年前

    您可以检查MSIInstaller事件,以找到卸载失败的线索:

    Get-WinEvent -computername <computername> -ProviderName MSIInstaller -Maxevents 30
    

    您还可以使用 /le '<logfilepath>' 添加到调用 msiexec.exe 并检查结果。

    我相信msi安装/卸载操作是异步的。您可能需要在pssession中等待,直到安装完成。

    McAfee代理有时需要 frminst.exe /forceuninsall 待移除。