title: How to (silently) uninstall MySQL on 32 and 64 bit Windows
body: <p>We are using Install4J for our current version of our software and install MySQL 5.1 silently during the installation.</p>
  
  <p>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:</p>
  
  <pre><code>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 &amp;&amp; displayVersion.toString().equals(installedMysqlVersion)
                    &amp;&amp; displayName != null &amp;&amp; displayName.toString().startsWith("MySQL Server") )
    {
      Util.logInfo( null, "Found match, uninstall key: " + uninstallKey );
      context.setVariable( "mysqlUninstallKey", uninstallKey );
      break;
   }
  }
  </code></pre>
  
  <p>This will put the product code of MySQL Server 5.1 in the <code>mysqlUninstallKey</code> variable. After this step, I have an 'Run executable or batch file' step with the following settings:</p>
  
  <ul>
  <li>Executable: msiexec.exe</li>
  <li>Working Directory: ${installer:sys.system32Dir}</li>
  <li>Arguments: /I{installer:mysqlUninstallKey}</li>
  </ul>
  
  <p>This will (on 32-bit Windows XP) run the installer of MySQL server and then the user has to select 'remove' manually.</p>
  
  <p>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.</p>
  
  <p>Any idea what might be wrong ? Or maybe I am doing this totally wrong and there is a better way?</p>
  
  <p>I use Install4j 4.2.8.</p>