2012-05-31 135 views
2

我遇到了Windows更新靜默安裝的小問題。 爲什麼我需要它?我有一個系統磁盤的副本,我用來重新安裝win7(利用.net框架,Visual Studio,Java和50多個其他應用程序安裝一次)。 然後我需要安裝一些重要的更新。我編碼在c#中的小utillity,工作正常,除了 安裝不沉默,即使使用startInfo.Arguments = "/quiet/norestart/passive";。 不沉默:我的意思是至少有兩個窗口,如問我是否需要安裝或重新啓動選項。無聲安裝.msu Windows更新?

問題在另一個論壇發言How are people deploying HOTFIXES .msu files? 但解決方案有點不清楚。有人知道如何解決它嗎? 再次,startInfo.Arguments = "/quiet/norestart/passive";startInfo.Arguments = @"/qb!"+ "REBOOT=ReallySuppress"+ @"/qn";不工作,並在鏈接解釋爲什麼。 textBox1.Text是所有修補程序和更新在一個目錄中的位置。

{

 string[] filePaths = Directory.GetFiles(textBox1.Text); 
     ProcessStartInfo startInfo = new ProcessStartInfo(); 
     startInfo.CreateNoWindow = true; 
     startInfo.UseShellExecute = true; 
     startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; 
     //startInfo.Arguments = "/quiet/norestart/passive"; 

     for (int i = 0; i < filePaths.Length; i++) 
     { 
      label1.Text = "Working"; 
      startInfo.FileName = filePaths[i]; 
      startInfo.Arguments = @"/qb!"+ "REBOOT=ReallySuppress"+ @"/qn"; 

      try 
      { 
       Process.Start(startInfo.FileName).WaitForExit(); 

      } 
       catch (Exception exc) 
      { 
       MessageBox.Show(exc.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); 
      } 

     } 
     label1.Text = " Done "; 

     } 
+0

爲什麼使用逐字字符串文字不需要? '/'不是C#中的轉義字符。 – Joey

回答

1

一開始你只是參數串聯起來沒有空格,因此只有經過這可能是行不通的一個參數。嘗試

startInfo.Arguments = "/qb! REBOOT=ReallySuppress /qn" 
+0

我做到了,另有10多種格式。問題不在於參數,否則startInfo.Arguments =「/ quiet/norestart/passive」就足夠了。參見上面的鏈接。 – Poool777

+0

好吧,我試過了,沒有任何改變 - wuse仍然要求安裝?重啓? etc/ – Poool777

+0

但是「/ quiet/norestart/passive」不起作用,MS應用程序幾乎總是需要開關之間的空格,即「/ quiet/norestart/passive」 – Grhm

0

最後我繞過它使用純CMD線。除異常情況外,無提示安裝無窗口。

private void button1_Click(object sender, EventArgs e) 
    { 
     string[] filePaths = Directory.GetFiles(textBox1.Text); 
     Process process = new Process(); 
     process.StartInfo.FileName = "cmd.exe"; 
     process.StartInfo.CreateNoWindow = true; 
     process.StartInfo.UseShellExecute = false; 
     process.EnableRaisingEvents = false; 

     for (int i = 0; i < filePaths.Length; i++) 
     { 
      if (i == 0) { label1.Text = "Working On first task"; } 
      process.StartInfo.Arguments = "/C " + "@" + "\"" + filePaths[i] + "\"" + " /quiet /norestart"; 
      process.Start(); 
      process.WaitForExit(); 
      label1.Text = (100 * i/filePaths.Length).ToString() + " % is done"; 

     } 
     label1.Text = "Done"; 

    }