繁体   English   中英

从特定字符串开始卸载所有软件

[英]Uninstall all software starting with a specific string

此问题之后 ,我想卸载所有National Instrument软件。 这里首先进入CMD中的wmic 然后使用命令product get name我得到一堆软件,所有这些都是从NI开始的:

NI Logos 19.0
NI Trace Engine
NI-MXDF 19.0.0f0 for 64 Bit Windows
WIF Core Dependencies Windows 19.0.0
NI-VISA USB Passport 19.0.0
NI-VISA SysAPI x64 support 19.0.0
NI Controller Driver 19.0 64-bit
NI ActiveX Container (64-bit)
Math Kernel Libraries
NI MXS 19.0.0
NI LabWindows/CVI 2019 Network Variable Library
NI-VISA GPIB Passport 19.0.0
NI LabWindows/CVI 2017 Low-Level Driver (Original)
NI-RPC 17.0.0f0 for Phar Lap ETS
NI LabWindows/CVI 2017 .NET Library (64-bit)
...

我可以单独卸载它们,例如:

product where name="NI Logos 19.0" call uninstall

然后我必须选择y / Y 鉴于我必须卸载很多这些软件,我想知道如何自动化这个过程。 步骤应该是这样的:

  1. 找到以NI开头的product get name所有行,并列出其中的列表
  2. 上面运行product where name=list[i] call uninstall列表中的for循环, product where name=list[i] call uninstall使用默认的y / Y product where name=list[i] call uninstall

如果你能帮我解决这个问题,我将不胜感激。 感谢您的支持。

PS Powershell解决方案也可以。 事实上,使用任何其他方式卸载所有这些的任何其他解决方案对我来说都是可以的。

您应该能够将Like运算符与一起使用。

WMIC Product Where "Name Like 'NI%'" Call Uninstall /NoInteractive

WMIC Product Where "Name Like 'NI%%'" Call Uninstall /NoInteractive

没有任何命令行选项记录为可用于Uninstall调用,因此这里提供的/NoInteractive比希望提示的最终解决方案更有希望。

如果应用程序是从MSI安装的,则可以使用以下PowerShell代码。 如果使用了其他一些安装程序,则可以将静默卸载参数添加到循环中的$uninstallString

$productNames  = @("^NI")
$uninstallKeys = @('HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
                   'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall')

foreach ($key in (Get-ChildItem $uninstallKeys)) 
{
    foreach ($productName in $productNames)
    {
        $name = $key.GetValue("DisplayName")
        if ($name -match $productName) 
        {
            $uninstallString = $key.GetValue("UninstallString")
            if ($uninstallString -match "^msiexec(\.| )")
            {
                $uninstallString = ($uninstallString -replace "/I{","/X{" -replace "/X{", '/X "{' -replace "}",'}"')  + " /qn /norestart"
            }

            Write-Host "Removing '$name' using '$uninstallString'..."
            & cmd.exe /C $uninstallString
        }
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM