简体   繁体   English

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

[英]How to programmatically uninstall an application in Windows?

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 Installer。

Thanks a bunch! 谢谢你!

Deployement Project in Visual Studio has a build-in feature to remove previous versions of your application. Visual Studio中的Deployement Project具有内置功能,可以删除以前版本的应用程序。

Check the "RemovePreviousVersions" property in the Deployement Project Properties. 检查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. 安装程序检查UpgradeCode和ProductCode属性以确定是否应删除早期版本。 The UpgradeCode must be the same for both versions; 两个版本的UpgradeCode必须相同; the ProductCode must be different. ProductCode必须不同。

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]

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 Installer(* .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 . 请参阅此MSDN有关创建自定义操作的文章。 It involves creating a new class library, adding an System.Configuration.Install.Installer class, adding it as an output to the setup project, and then selecting it as a custom action. 它涉及创建一个新的类库,添加一个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. 从这里:您需要编写代码以删除安装目录和AppData配置文件。 This article on how to set Custom Action Data may be helpful. 本文介绍如何设置自定义操作数据可能会有所帮助。

Good luck. 祝好运。

HTH, HTH,

Dennis 丹尼斯

If this you program then that's a simple reverse batch. 如果你编程,那么这是一个简单的反向批处理。
Or you could use some installer/uninstaller builder like NSIS 或者你可以使用像NSIS这样的安装程序/卸载程序构建器

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

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