WinRAR解压

#region WinRAR解压
/// <summary>
/// 利用 WinRAR 进行解压缩 (前提是电脑上面安装了WinRAR解压软件)
/// </summary>
/// <param name="path">文件解压路径(绝对)</param>
/// <param name="rarPath">将要解压缩的 .rar 文件的存放目录(绝对路径)</param>
/// <param name="rarName">将要解压缩的 .rar 文件名(包括后缀)</param>
/// <returns>true 或 false。解压缩成功返回 true,反之,false。</returns>
public static bool UnRAR(string path, string rarPath, string rarName)
{
bool flag = false;
string rarexe;
RegistryKey regkey;
Object regvalue;
string cmd;
ProcessStartInfo startinfo;
Process process;
try
{
//不同机器的winrar的注册码不同,根据情况而定路径 Applications\WinRAR.exe\shell\open\command
regkey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Classes\WinRAR\shell\open\command"); //目的是为了找到winrar.exe的路径,然后启动WinRAR
regvalue = regkey.GetValue("");
rarexe = regvalue.ToString();
regkey.Close();
rarexe = rarexe.Substring(1, rarexe.Length - 7);
Directory.CreateDirectory(path);
//解压缩命令,相当于在要压缩文件(rarName)上点右键 ->WinRAR->解压到当前文件夹
cmd = string.Format("x {0} {1} -y", rarName, path);
startinfo = new ProcessStartInfo();
startinfo.FileName = rarexe;
startinfo.Arguments = cmd;
startinfo.WindowStyle = ProcessWindowStyle.Hidden;
startinfo.WorkingDirectory = rarPath;
process = new Process();
process.StartInfo = startinfo;
process.Start();
process.WaitForExit();
if (process.HasExited)
{
flag = true;
}
process.Close();
}
catch (Exception e)
{
throw e;
}
return flag;
}

#endregion

WinRAR解压,布布扣,bubuko.com

WinRAR解压

上一篇:Google Code Jam 2012 round 2 problem A: Swinging Wild


下一篇:CAD文件大小怎么减少?