如何以编程方式卸载 Windows 中的应用程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3922271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:24:00  来源:igfitidea点击:

How to programmatically uninstall an application in Windows?

c#windowsuninstall

提问by Andrei

We are releasing a new version of our application and we would like it to be able to uninstall the previous installed version from the client's computer.

我们正在发布我们应用程序的新版本,我们希望它能够从客户端的计算机上卸载以前安装的版本。

How would we be able to do that?

我们如何才能做到这一点?

edit: I'm installing this application (and also the previous version) with a deployment project in Visual Studio, so I assume it is a Windows Installer.

编辑:我正在使用 Visual Studio 中的部署项目安装此应用程序(以及以前的版本),因此我假设它是 Windows 安装程序。

Thanks a bunch!

谢谢一堆!

回答by tpol

Deployement Project in Visual Studio has a build-in feature to remove previous versions of your application.

Visual Studio 中的部署项目有一个内置功能来删除应用程序的先前版本。

Check the "RemovePreviousVersions" property in the Deployement Project Properties.

检查部署项目属性中的“RemovePreviousVersions”属性。

http://msdn.microsoft.com/library/y63fxdw6.aspx

http://msdn.microsoft.com/library/y63fxdw6.aspx

Edit:

编辑

from MSDN:

来自 MSDN:

The installer checks UpgradeCode and ProductCode properties to determine whether the earlier version should be removed. The UpgradeCode must be the same for both versions; the ProductCode must be different.

安装程序检查 UpgradeCode 和 ProductCode 属性以确定是否应删除早期版本。两个版本的 UpgradeCode 必须相同;ProductCode 必须不同。

回答by James - built2order

If your using batch or another automated deployment tool for your releases, you can easily uninstall an MSI product using the following command line:

如果您为您的版本使用批处理或其他自动部署工具,您可以使用以下命令行轻松卸载 MSI 产品:

 msiexec [/uninstall | /x] [Product.msi | ProductCode]

回答by Dennis

The Microsoft Installer (*.msi) format supports what you want do to, unfortunately Visual Studio only offers limited customisation and is designed to be used for basic projects.

Microsoft 安装程序 (*.msi) 格式支持您想要执行的操作,遗憾的是 Visual Studio 仅提供有限的自定义并且旨在用于基本项目。

There are a lot of resources out there on this topic and many other people asking similar questions. My best advice would be spent some time researching the MSDN documentation.

有很多关于这个主题的资源,还有很多其他人提出了类似的问题。我最好的建议是花一些时间研究 MSDN 文档。

...

...

Update

更新

OK. After spending 30 minutes reading a few articles, I think it may be possible using a custom action that you package with your new installer.

好的。在花了 30 分钟阅读了几篇文章后,我认为可以使用与新安装程序一起打包的自定义操作。

Follow this MSDN article on creating a Custom Action. It involves creating a new class library, adding an System.Configuration.Install.Installerclass, adding it as an output to the setup project, and thenselecting it as a custom action.

请按照有关创建自定义操作的MSDN 文章进行操作。它涉及创建一个新的类库,添加一个System.Configuration.Install.Installer类,将其作为输出添加到安装项目,然后选择它作为自定义操作。

To view your custom actions tab, right-click on the setup project and select View > Custom Actions.

要查看自定义操作选项卡,请右键单击安装项目并选择查看 > 自定义操作。

From here: you will need to write the code to remove the installation directory and AppData profile. This article on how to set Custom Action Datamay be helpful.

从这里开始:您需要编写代码来删除安装目录和 AppData 配置文件。这篇关于如何设置自定义操作数据的文章可能会有所帮助。

Good luck.

祝你好运。

HTH,

哈,

Dennis

丹尼斯

回答by pinichi

If this you program then that's a simple reverse batch.
Or you could use some installer/uninstaller builder like NSIS

如果这是您编程,那么这就是一个简单的反向批处理。
或者您可以使用一些安装程序/卸载程序构建器,例如NSIS