简体   繁体   English

从代码启动卸载程序

[英]Starting an uninstaller from code

I would like to add an "Uninstall" button to my program that will start the uninstaller to remove the program and then immediately quit. 我想在我的程序中添加一个“卸载”按钮,它将启动卸载程序以删除程序,然后立即退出。 What's the best way to a) determine if there is an uninstaller present, and b) find the correct uninstaller and launch it? 什么是a)确定是否存在卸载程序的最佳方法,以及b)找到正确的卸载程序并启动它?

Can I use the registry in a reliable manner? 我可以以可靠的方式使用注册表吗? I recall using the registry before to fix some broken installations and was thinking I could iterate over the entries and identify the appropriate one, but I worry that using the registry might not be reliable and/or work on all systems? 我记得之前使用注册表来修复一些破坏的安装,并且认为我可以迭代条目并确定适当的条目,但我担心使用注册表可能不可靠和/或在所有系统上工作?

Another thought is that I could actually store the uninstall information to the registry during the installation itself, and then use that information to somehow find the correct uninstaller. 另一个想法是我实际上可以在安装过程中将卸载信息存储到注册表中,然后使用该信息以某种方式找到正确的卸载程序。 That seems like it would be the most reliable method, but is there such an identifier that I could store that I could then pass back to Windows Installer? 这似乎是最可靠的方法,但有没有我可以存储的标识符,然后我可以传回Windows Installer?

Since you taged this with windows-installer, I will assume that you are distributing your application using an MSI. 由于您使用Windows安装程序进行了此操作,我将假设您使用MSI分发应用程序。 That said, you can call msiexec /x {ProductCode} from your application to initial the uninstall. 也就是说,您可以从应用程序中调用msiexec / x {ProductCode}来初始化卸载。 You can obtain the product code by having the installer write to a registry key/value that your application can read or you can hard code it or your UpgradeCode in your application. 您可以通过让安装程序写入应用程序可以读取的注册表项/值来获取产品代码,也可以在应用程序中对其进行硬编码或升级代码。 If you hard code the UpgradeCode you'll have to call into the Windows Installer API to find out the installed ProductCode for that UpgradeCode. 如果您对UpgradeCode进行硬编码,则必须调用Windows Installer API以找出该UpgradeCode的已安装ProductCode。

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

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