2011-08-26 140 views
2

我使用C#爲我安裝自定義操作編寫InstallerClass,我可以成功運行使用InstallerClass外部EXE(安裝),但是當我嘗試在InstallerClass使用/quiet,它不安裝exe。但我可以在命令提示符下使用/quiet以靜默方式成功安裝。靜默安裝使用C#

是否有任何理由爲此或以其他方式如何使用C#安靜模式安裝?

編輯:

以下是我的Commit方法中使用的代碼(重寫):

Process p = new Process(); 
p.StartInfo.UseShellExecute = false; 
p.StartInfo.FileName = pathExternalInstaller; 
p.StartInfo.Arguments = "/quiet"; 
p.Start(); 

感謝

+0

請出示一些源代碼 - ESP。您調用外部EXE進行安裝的部分。 – Yahia

+0

@ Yahia:我添加了我用過的代碼... –

+0

您是否(成功)嘗試直接使用'/ quiet'選項運行「外部安裝程序」,例如:從命令提示符? –

回答

7

這裏是我用來做一個安靜的安裝和卸載:

public static bool RunInstallMSI(string sMSIPath) 
    { 
     try 
     { 
      Console.WriteLine("Starting to install application"); 
      Process process = new Process(); 
      process.StartInfo.FileName = "msiexec.exe"; 
      process.StartInfo.Arguments = string.Format(" /qb /i \"{0}\" ALLUSERS=1", sMSIPath);  
      process.Start(); 
      process.WaitForExit(); 
      Console.WriteLine("Application installed successfully!"); 
      return true; //Return True if process ended successfully 
     } 
     catch 
     { 
      Console.WriteLine("There was a problem installing the application!"); 
      return false; //Return False if process ended unsuccessfully 
     } 
    } 

    public static bool RunUninstallMSI(string guid) 
    { 
     try 
     { 
      Console.WriteLine("Starting to uninstall application"); 
      ProcessStartInfo startInfo = new ProcessStartInfo("cmd.exe", string.Format("/c start /MIN /wait msiexec.exe /x {0} /quiet", guid)); 
      startInfo.WindowStyle = ProcessWindowStyle.Hidden; 
      Process process = Process.Start(startInfo); 
      process.WaitForExit(); 
      Console.WriteLine("Application uninstalled successfully!"); 
      return true; //Return True if process ended successfully 
     } 
     catch 
     { 
      Console.WriteLine("There was a problem uninstalling the application!"); 
      return false; //Return False if process ended unsuccessfully 
     } 
    } 
+0

我在調用中調用了'RunInstallMSI'在CommitlerClass中提交,但它表示另一個安裝已經在進行中,並且不允許在應用程序安裝期間安裝外部exe文件....任何原因或解決方案? –

+0

http://support.microsoft.com/kb/236456 –

1

P此爲我工作:)

 Process process = new Process(); 
     process.StartInfo.FileName = @"C:\PATH\Setup.exe"; 
     process.StartInfo.Arguments = "/quiet"; 
     process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
     process.Start(); 
     process.WaitForExit();