问题
We are using Install4J for our current version of our software and install MySQL 5.1 silently during the installation.
For the next version of our software, if it is an upgrade, I want to remove MySQL 5.1 and install 5.5. Ideally, the uninstall should go silently, but not a hard requirement. I managed to get it working on 32-bit Windows XP, but not on 64-bit Windows 7. This is what I have so far:
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;
}
}
This will put the product code of MySQL Server 5.1 in the mysqlUninstallKey
variable. After this step, I have an 'Run executable or batch file' step with the following settings:
- Executable: msiexec.exe
- Working Directory: ${installer:sys.system32Dir}
- Arguments: /I{installer:mysqlUninstallKey}
This will (on 32-bit Windows XP) run the installer of MySQL server and then the user has to select 'remove' manually.
On 64-bit Windows 7, it just shows a dialog showing all the command line flags and their explanation, so msiexec.exe is being started, but the argument I pass into it is not recognized.
Any idea what might be wrong ? Or maybe I am doing this totally wrong and there is a better way?
I use Install4j 4.2.8.
回答1:
Thanks to the comment of @marcus-adams, I figured it out. You need to use '/qn', '/x' and '{installer:mysqlUninstallKey}' as separate arguments in the 'Run executable or batch file' action of install4j. If you use 1 argument with spaces, it does not work. With this it works on 32-bit and 64-bit.
来源:https://stackoverflow.com/questions/10282814/how-to-silently-uninstall-mysql-on-32-and-64-bit-windows