萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> asp.net編程 >> c# 調用WinRAR 實現文件壓縮、文件解壓WinRAR命令行參數不彈窗

c# 調用WinRAR 實現文件壓縮、文件解壓WinRAR命令行參數不彈窗

 //壓縮程序安裝路徑  

            string pathExe = Application.StartupPath + @"WinRAR.exe";  
            Process p = new Process();  
            p.StartInfo.FileName = pathExe;  
            p.StartInfo.Arguments = @"a -as -r -afzip -ed -hp123 -ibck -nul -m5 -mt5 d:kldder d:easyui";  
            p.StartInfo.CreateNoWindow = true;  
            p.StartInfo.RedirectStandardInput = true;  
            p.StartInfo.RedirectStandardError = false;  
            p.StartInfo.RedirectStandardOutput = true;  
            p.StartInfo.UseShellExecute = false;  
            p.StartInfo.ErrorDialog = false;  
            p.Start();  
            int idx = 1;  
            while (!p.HasExited)  
            {  
                idx++;  
                p.WaitForExit(500);  
                if (idx == 5)  
                {  
                    p.Kill();  
                }  
            }  
            p.Close();  
            p.Dispose();  
            /* 
             * <命令> -<開關1> -<開關N> <壓縮文件 > <文件...> <@列表文件...> <解壓路徑> 
             *壓縮 a      a -as -ed -inul -afrar -df -ibck -m4 -mt3 -or -y -hp123 d:aa d:aa.txt 
             *解壓 x      x -hp123 -ibck -inul -y -mt5 d:aa.rar a: 
             *a d:Info.zip D:easyui 
             *-af 指定格式 -afzip -afrar 
             *-as 在當前添加的文件列表中不存在的被壓縮文件,將會從壓縮文件中刪除 
             *-df 壓縮後刪除源文件 
             *-dr 刪除到回收站 
             *-ed 不添加空文件夾 
             *-hp 添加密碼 -hp123456 
             *-ibck 後台運行 
             *-inul 禁止錯誤信息 
             *-loff 壓縮完成後 關閉電源 
             *-m0 存儲 添加文件到壓縮文件但是不壓縮   
             *-m1 最快 最快速的方法 ( 最低的壓縮比)  
             *-m2 快速 快速壓縮方法  
             *-m3 標准 標准 (默認 ) 壓縮方法  
             *-m4 較好 較好的壓縮方法 (較高的壓縮比)  
             *-m5 最優 最優的壓縮方法 (最高壓縮比但是速度也最慢) 
             *-mtN 線程 -mt5 1~32 
             *-or 自動重命名文件 
             *-r 連同子文件 
             *-z 壓縮後測試文件 
             *-y 所有彈窗選擇"是" 
             */  

*可以直接將winrar.exe 拷貝到 根目錄下運行
*不彈窗只需要打開開光 -ibck -inul 即可

copyright © 萬盛學電腦網 all rights reserved