gpt4 book ai didi

c# - 在WPF应用程序中使用powershell通过uninstallString卸载应用程序

转载 作者:行者123 更新时间:2023-12-02 08:33:14 27 4
gpt4 key购买 nike

我正在尝试在 WPF 应用程序中使用以下 Powershell 脚本卸载软件

get-package |where name -like "Notepad++ (64-bit x64)" |% { & $_.Meta.Attributes["UninstallString"] /S}

上述命令仅适用于Notepad++(64位x64),但当我尝试使用Git版本2.25.1TortoiseGit 2.10等软件时失败。 0.0(64 位)

对于 Git 版本 2.25.1

get-package |where name -like "Git version 2.25.1" |% { & $_.Meta.Attributes["UninstallString"] /S} 

我收到以下错误:

& : The term '"C:\Program Files\Git\unins001.exe"' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:59 + ... "Git version 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} 

我收到以下错误:

The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object. At line:1 char:70 + ... t 2.10.0.0 (64 bit)" |% { & $_.Meta.Attributes["UninstallString"] /S} + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : BadExpression

我还尝试使用 WMI 对象 powershell 脚本,下面是脚本

Get-WmiObject -Class Win32_Product | Where {$_.Name -like \"{returnStr}\"}  | foreach {$_.Uninstall()}".Replace("{returnStr}", Notepad++ (64-bit x64))   

以上脚本仅适用于通过 MSI 安装的软件

如果有人对如何进行有任何建议,我们将不胜感激!

最佳答案

您可以在这里找到您 friend 的 Uninstall-Package:

get-package | where-object name -like "Notepad++ (64-bit x64)" | ForEach {uninstall-package}

关于c# - 在WPF应用程序中使用powershell通过uninstallString卸载应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60771789/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com