2014-06-20 54 views
0

我想讓winrar Process窗口不可見。當我使用Process類啓動winrar時,如何使窗口不可見

這行代碼似乎沒有任何效果:

 //the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 

我怎樣才能做到這一點的窗口保持隱藏?

這是我用WinRAR的啓動代碼:

 public void compress(string inputfilename, string outputfilename, string workingfolder) 
    { 
     string the_rar; 
     RegistryKey the_Reg; 
     object the_Obj; 
     string the_Info; 
     ProcessStartInfo the_StartInfo; 
     Process the_Process; 
     try 
     { 
      the_Reg = Registry.ClassesRoot.OpenSubKey(@"WinRAR\shell\open\command");//for winrar path 
      the_Obj = the_Reg.GetValue(""); 
      the_rar = the_Obj.ToString(); 
      the_Reg.Close(); 
      the_rar = the_rar.Substring(1, the_rar.Length - 7); 
      the_Info = " a " + " " + outputfilename + " " + " " + inputfilename;//i dare say for parameter 
      the_StartInfo = new ProcessStartInfo(); 

      the_StartInfo.FileName = the_rar; 
      the_StartInfo.Arguments = the_Info; 
      the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
      the_StartInfo.WorkingDirectory = workingfolder; 
      the_Process = new Process(); 
      the_Process.StartInfo = the_StartInfo; 
      the_Process.Start();//starting compress Process 
      the_Process.Close(); 
      the_Process.Dispose(); 
     } 
     catch 
     { 
     } 
    } 
+0

爲什麼不使用本機庫而不是使用shelling? –

+0

@Kaboo'WinRar'附帶一個命令行工具('Rar.exe'和'Unrar.exe')來壓縮/解壓檔案。您可能想嘗試使用它而不是使用GUI('WinRar.exe')。 – IronGeek

回答

2
當您使用ProcessWindowStyle.Hidden還必須設置ProcessStartInfo.UseShellExecute假

原因:

如果UseShellExecute屬性爲true或用戶名和密碼屬性不爲空,則CreateNoWindow屬性值將被忽略,並創建一個新的窗口。

public void compress(string inputfilename, string outputfilename, string workingfolder) 
{ 
    string the_rar; 
    RegistryKey the_Reg; 
    object the_Obj; 
    string the_Info; 
    ProcessStartInfo the_StartInfo; 
    Process the_Process; 
    try 
    { 
     the_Reg = Registry.ClassesRoot.OpenSubKey(@"WinRAR\shell\open\command");//for winrar path 
     the_Obj = the_Reg.GetValue(""); 
     the_rar = the_Obj.ToString(); 
     the_Reg.Close(); 
     the_rar = the_rar.Substring(1, the_rar.Length - 7); 
     the_Info = " a " + " " + outputfilename + " " + " " + inputfilename;//i dare say for parameter 
     the_StartInfo = new ProcessStartInfo(); 

     the_StartInfo.FileName = the_rar; 
     the_StartInfo.Arguments = the_Info; 
     the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden; 
     the_StartInfo.UseShellExecute = false; 
     the_StartInfo.WorkingDirectory = workingfolder; 
     the_Process = new Process(); 
     the_Process.StartInfo = the_StartInfo; 
     the_Process.Start();//starting compress Process 
     the_Process.Close(); 
     the_Process.Dispose(); 
    } 
    catch (Exception ex) 
    { 
     System.Diagnostics.Debug.WriteLine(ex.Message); 
    } 
} 
+1

請修復空捕獲... – rene

+0

@rene好吧我修好了 –

相關問題