如何(无提示)在32位和64位Windows上卸载MySQL
问题描述:
我们使用Install4J作为我们当前版本的软件,并在安装过程中静默安装MySQL 5.1。如何(无提示)在32位和64位Windows上卸载MySQL
对于我们软件的下一个版本,如果是升级,我想删除MySQL 5.1并安装5.5。理想情况下,卸载应该静静地进行,但不是一个硬性要求。我设法得到它的工作在32位的Windows XP,但不能在64位Windows 7这是我到目前为止有:
String[] uninstallKeys = WinRegistry.getSubKeyNames(RegistryRoot.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
for(String uninstallKey : uninstallKeys)
{
Object displayVersion = WinRegistry.getValue(RegistryRoot.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + uninstallKey, "DisplayVersion");
Object displayName = WinRegistry.getValue(RegistryRoot.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + uninstallKey, "DisplayName");
if(displayVersion != null && displayVersion.toString().equals(installedMysqlVersion)
&& displayName != null && displayName.toString().startsWith("MySQL Server"))
{
Util.logInfo(null, "Found match, uninstall key: " + uninstallKey);
context.setVariable("mysqlUninstallKey", uninstallKey);
break;
}
}
这将使MySQL服务器5.1的产品代码在mysqlUninstallKey
变量。这一步后,我有一个 '运行可执行文件或批处理文件' 的步骤以下设置:
- 可执行文件:msiexec.exe的
- 工作目录:$ {安装程序:sys.system32Dir}
- 参数:/I {installer:mysqlUninstallKey}
这将(在32位Windows XP上)运行MySQL服务器的安装程序,然后用户必须手动选择“删除”。
在64位Windows 7上,它只显示一个对话框,显示所有命令行标志及其解释,因此msiexec.exe正在启动,但我传入的参数未被识别。
任何想法可能是错误的?或者,也许我这样做完全错了,还有更好的办法吗?
我使用Install4j 4.2.8。
答
感谢@ marcus-adams的评论,我想通了。您需要在install4j的“运行可执行文件或批处理文件”操作中将'/ qn','/ x'和'{installer:mysqlUninstallKey}'作为单独的参数。如果对空格使用1个参数,则不起作用。有了它,它可以在32位和64位上运行。
要删除旧版本,请使用'msiexec.exe/qn/x {目标产品代码}'。 – 2012-04-23 16:51:17