1、 開始使用的msi工程類型。網上找了資料, 在kevin的博客里找到這條方法 可以通過刪除Execute Sequence中的RegisterProduct和PublishProduct兩個CA實現同樣的需求。
試過之后確實是可以 重復安裝的,但是 執行開始菜單中的卸載是無法卸載的執行有下圖的 錯誤:
問過人也找過資料 說將它的屬性Arguments、Target 分別設為:/x [ProductCode]、 [SystemFolder]msiexec.exe
即可卸載,但不知道為什么我們的產品 GUID沒變過,執行卸載的時候,提示 不是一個產品。如下圖
而控制面板是不能顯示該程序的。所以此方法不可行。
2、 換了個工程類型,使用 installscript工程類型,此類型的 腳本中 advanced下面有個 OnShowUI(msi沒有這個方法),即存放的檢測是已安裝、更新、還是第一次安裝 的腳本,修改邏輯
如果是第一次安裝執行OnFirstUIbefore() ;(不必修改)
如果是更新執行 OnUpdateUIBefore();(不必修改)
如果是已經安裝 默認是執行的OnMaintUIBefore(); 則修改為 繼續執行 OnFirstUIbefore();
此時調試 覆蓋安裝會覆蓋不了文件。調用一個修復方法FeatureReinstall(); 就可以 覆蓋文件了
在 卸載的快捷方式中添加一個參數 -removeonly,檢測判斷此參數為卸載功能,即 開始菜單的卸載可以正常卸載。
注意:這里如果不加這個參數執行卸載也是覆蓋安裝
OnShowUI() 修改代碼如下:
function OnShowUI() BOOL bMaintenanceMode, bUpdateMode; string szIgnore, szTitle; begin // Enable dialog caching Enable( DIALOGCACHE ); // Determine what events to show. bUpdateMode = FALSE; bMaintenanceMode = FALSE; // Remove this to disabled update mode. if( UPDATEMODE ) then bUpdateMode = TRUE; endif; // Remove this to disable maintenance mode. if ( MAINTENANCE ) then bMaintenanceMode = TRUE; endif; // Show appropriate UI if( REMOVEONLY ) then // MessageBox ("卸載", SEVERE); OnMaintUIBefore(); else if( bUpdateMode ) then // MessageBox ("更新", SEVERE); OnUpdateUIBefore(); else if ( bMaintenanceMode ) then if( MessageBox( "您已安裝最新版本,是否覆蓋安裝?" , MB_YESNO ) != IDYES ) then abort; endif; OnFirstUIBefore(); FeatureReinstall(); else // MessageBox ("第一次安裝", SEVERE); OnFirstUIBefore(); endif; endif; endif; // Move Data OnMoveData(); //OnFirstUIAfter(); if( REMOVEONLY ) then OnMaintUIAfter(); else OnFirstUIAfter(); endif; // Disable dialog caching Disable(DIALOGCACHE); end;