2014-02-13 189 views
1

是否可以從自定義操作中正常退出msi installar?停止自定義操作的安裝

我使用Visual Studio安裝項目來創建msi,並且我添加了一個自定義動作exe來安裝。如果我從exe中返回非零值,它會終止安裝。但它顯示一個錯誤。我需要退出安裝而不顯示錯誤。

謝謝。

回答

1

試試這個代碼在你的安裝程序類。我希望它能解決你的問題。

protected override void OnBeforeInstall(IDictionary savedState) 
     { 
      if (LaunchOnBeforeInstall()) 
      { 
       base.OnBeforeInstall(savedState); 
      } 
      else 
      { 
       throw new Exception("You cancelled installation"); 
      } 
     } 
     public bool LaunchOnBeforeInstall() 
     { 
      Form2 frm2 = new Form2(); 
      DialogResult result = frm2.ShowDialog(); 
      if (result == DialogResult.Cancel) 
      { 
       return false; 
      } 
      else 
      { 
       return true; 
      } 
     } 

而且也把「NOTPREVIOUSVERSIONSINSTALLED」

enter image description here