日期:2014-05-18  浏览次数:20754 次

那位大侠帮忙看看 c# 解压出现为找到解压文件
C# code

     //解压
        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();
                
            }
        }




 安装路径 有update.rar 文件 但提示找不到压缩文件 求大侠指点


------解决方案--------------------
你看看 rarPath 是什么内容,不一定你就能从注册表中读到数据,或者你将字符串处理错误
------解决方案--------------------
是否考虑过windows7之类的用户安全权限,读取注册表要不要管理员权限?