2012-04-23 83 views
1

我們使用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。

+1

要刪除舊版本,請使用'msiexec.exe/qn/x {目標產品代碼}'。 – 2012-04-23 16:51:17

回答

2

感謝@ marcus-adams的評論,我想通了。您需要在install4j的「運行可執行文件或批處理文件」操作中將'/ qn','/ x'和'{installer:mysqlUninstallKey}'作爲單獨的參數。如果對空格使用1個參數,則不起作用。有了它,它可以在32位和64位上運行。