2015-10-06 175 views
0

我正在創建一個應用程序,並且我要求在安裝過程中應用程序會卸載一些其他已安裝的程序,所以我首先做的是創建一個控制檯應用程序,用於卸載程序並直到出現問題,我將這個控制檯應用程序添加爲安裝程序中的自定義操作並構建瞭解決方案,但在安裝時,卸載程序不起作用。在安裝和部署過程中卸載應用程序

對不起,我英文不好:)。

我使用下面的代碼進行卸載。

 string UninstallCommandString = "/x {0} /qn"; 
     Process process = new Process(); 
     ProcessStartInfo startInfo = new ProcessStartInfo(); 
     process.StartInfo = startInfo; 

     startInfo.UseShellExecute = false; 
     startInfo.RedirectStandardError = true; 

     startInfo.FileName = "msiexec.exe"; 
     startInfo.Arguments = string.Format(UninstallCommandString, "{CCB85747-267D-45C6-AC32-7979ADFCD2D8}"); 
     process.Start(); 
     process.WaitForExit(); 

     string UninstallCommandString2 = "/x {0} /qn"; 
     Process process2 = new Process(); 
     ProcessStartInfo startInfo2 = new ProcessStartInfo(); 
     process2.StartInfo = startInfo2; 

     startInfo2.UseShellExecute = false; 
     startInfo2.RedirectStandardError = true; 

     startInfo2.FileName = "msiexec.exe"; 
     startInfo2.Arguments = string.Format(UninstallCommandString2, "{7A8A8C03-6BEA-45B4-BAD9-EBC5790A037A}"); 
     process2.Start(); 
     process2.WaitForExit(); 


     string UninstallCommandString3 = "/x {0} /qn"; 
     Process process3 = new Process(); 
     ProcessStartInfo startInfo3 = new ProcessStartInfo(); 
     process3.StartInfo = startInfo3; 

     startInfo3.UseShellExecute = false; 
     startInfo3.RedirectStandardError = true; 

     startInfo3.FileName = "msiexec.exe"; 
     startInfo3.Arguments = string.Format(UninstallCommandString3, "{6AFDD6D0-3F33-45F0-B058-677F2080AE22}"); 
     process3.Start(); 
     process3.WaitForExit(); 

     string UninstallCommandString4 = "/x {0} /qn"; 
     Process process4 = new Process(); 
     ProcessStartInfo startInfo4 = new ProcessStartInfo(); 
     process4.StartInfo = startInfo4; 

     startInfo4.UseShellExecute = false; 
     startInfo4.RedirectStandardError = true; 

     startInfo4.FileName = "msiexec.exe"; 
     startInfo4.Arguments = string.Format(UninstallCommandString4, "{ACC5E4C6-B4D2-4227-B577-95D511C05A6E}"); 
     process4.Start(); 
     process4.WaitForExit(); 

回答

0

您無法從自定義操作執行安裝或卸載,並且特別適用於VS安裝項目。一次只允許一個MSI操作。

通常情況下,您需要進行重大升級,即VS安裝項目中的RemovePreviousVersions,但VS不支持升級安裝程序的當前UpgradeCode。另一個工具(如Wix)會讓你列出一堆升級代碼,你的安裝會自動卸載相關的產品。

所以這取決於您的工作流程要求。你可以將你的設置壓縮成一個運行你的卸載的自解壓exe文件,然後運行你的setup.exe(如果你有安裝的先決條件)或者只是安裝你的MSI。或者,您可以使用MSI編輯器工具(如Orca)將這些MSI產品的UpgradeCodes添加到您的MSI的升級表中,並且您已經構建了RemovePreviousVersions升級,然後將其卸載。沒有太多的答案,但你正在嘗試做一些Windows Installer不支持的操作(來自自定義操作的MSI操作),VS不支持(卸載其他產品的升級)。

+0

是的,感謝您的回覆,我得到了這一點,我得到了解決方案,比我想象的要容易,有兩種方法可以做到這一點。 1. InstallShield自定義操作,在初始化之後(在對話框之前):如果我在此部分中運行我的代碼完美工作,因爲它在安裝之前完成,問題在於,它不適用於遠程部署和無提示安裝。 2. InstallShield升級路徑:只需添加要卸載的.msi程序文件,並且完美無瑕! –

相關問題