如何调用RAR生成exe自解压文件
如何调用RAR生成EXE自解压文件,要设置密码,使用最好的压缩方式,固实压缩文件,锁定压缩文件,从文件读取注释添加到RAR中.
可以带命令符运行压缩软件rar.exe主程序来实现,比如解压 "x 压缩包 目标位置 -y"
/// <summary>
/// 解压缩
/// </summary>
/// <param name="unRarPatch">解压</param>
/// <param name="rarName"></param>
/// <returns></returns>
public string unCompressRAR(string unRarPatch, string rarName)
{
string the_rar;
RegistryKey the_Reg;
object the_Obj;
string the_Info;
try
{
the_Reg = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\WinRAR.exe");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
//the_rar = the_rar.Substring(1, the_rar.Length - 7);
if (Directory.Exists(unRarPatch) == false)
{
Directory.CreateDirectory(unRarPatch);
}
the_Info = "x " + rarName + " " + unRarPatch + " -y";
ProcessStartInfo the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = unRarPatch;//获取压缩包路径
Process the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
try
{
the_Process.Start();
the_Process.WaitForExit();
the_Process.Close();
}
catch
{
}
}
}