【发布时间】:2020-07-01 10:48:52
【问题描述】:
我正在尝试在 WPF 应用程序中使用以下 Powershell 脚本卸载软件
get-package |where name -like "Notepad++ (64-bit x64)" |% { & $_.Meta.Attributes["UninstallString"] /S}
上述命令仅适用于 Notepad++ (64-bit x64),但当我尝试使用 Git 版本 2.25.1 和 TortoiseGit 2.10 等软件时失败。 0.0(64 位)
对于 Git 版本 2.25.1
get-package |where name -like "Git version 2.25.1" |% { & $_.Meta.Attributes["UninstallString"] /S}
我收到以下错误:
&:无法识别术语“C:\Program Files\Git\unins001.exe” 作为 cmdlet、函数、脚本文件或可运行程序的名称。 检查名称的拼写,或者如果包含路径,请验证 路径正确,然后重试。在行:1 字符:59 + ... "Git 版本 2.25.1" |% { & $_.Meta.Attributes["UninstallString"] /S} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: ("C:\Program Files\Git\unins001.exe":String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
对于 TortoiseGit 2.10.0.0(64 位)
get-package |where name -like "TortoiseGit 2.10.0.0 (64 bit)" |% { & $_.Meta.Attributes["UninstallString"] /S}
我遇到以下错误:
管道元素中“&”之后的表达式产生了一个对象 无效。它必须产生一个命令名、一个脚本块或一个 命令信息对象。在行:1 字符:70 + ... t 2.10.0.0(64 位)" |% { & $_.Meta.Attributes["UninstallString"] /S} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : BadExpression
我也试过用WMI objects powershell script 下面是脚本
Get-WmiObject -Class Win32_Product | Where {$_.Name -like \"{returnStr}\"} | foreach {$_.Uninstall()}".Replace("{returnStr}", Notepad++ (64-bit x64))
以上脚本仅适用于通过 MSI 安装的软件
如果有人对如何继续提出建议,将不胜感激!
【问题讨论】:
标签: c# wpf powershell wmi