[英]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
鉴于我必须卸载很多这些软件,我想知道如何自动化这个过程。 步骤应该是这样的:
NI
开头的product get name
所有行,并列出其中的列表 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解决方案也可以。 事实上,使用任何其他方式卸载所有这些的任何其他解决方案对我来说都是可以的。
如果应用程序是从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.