日期:2014-05-18 浏览次数:20805 次
//解压 public bool DoUnPack() { bool r = false; // string strR = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "update"+"//"; string strR = Application.StartupPath + "//" + "update"; //MessageBox.Show(strR); Console.WriteLine("开始解压......"); RegistryKey reg; string rarPath; Process process = new Process(); try { reg = Registry.ClassesRoot.OpenSubKey(@"Applications\WinRar.exe\Shell\Open\Command"); rarPath = reg.GetValue("").ToString(); rarPath = rarPath.Substring(1, rarPath.Length - 7); process.StartInfo.FileName = rarPath; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; // -0+ 如果已经存在则覆盖 process.StartInfo.Arguments = string.Format(" x -o+ {0} {1}", strR, Application.StartupPath + "//");//这里是命令行请参考winrar的说明 //开始解压 process.Start(); while (!process.HasExited) { } //进程终止 if (process.HasExited) { int exitCode = process.ExitCode; if (exitCode == 0) { Console.WriteLine("{0} 正常完成", exitCode.ToString()); r= true; } else { Console.WriteLine("{0} 正常完成", exitCode.ToString()); } } Console.WriteLine("解压完成"); return r; } catch (Exception ex) { //MessageBox.Show("123"); throw ex; } finally { //释放资源 process.Close(); } }