[英]How to Check File Exist or Not in WinRAR, 7Zip, Zip, Tar, Winzip in C#
[英]Use winrar decompression how to check password
使用winrar解压缩,如何检测密码正确?
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_Info = "x " + rarName + " " + _unRarPath + " -y -p123456";
ProcessStartInfo the_StartInfo = new ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = _rarPath;//获取压缩包路径
Process the_Process = new Process();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
the_Process.WaitForExit();
希望此解决方案对您有所帮助。 这是原始帖子链接
public class ZipPasswordTester
{
public bool CheckPassword(Ionic.Zip.ZipEntry entry, string password)
{
try
{
using (var s = new PasswordCheckStream())
{
entry.ExtractWithPassword(s, password);
}
return true;
}
catch (Ionic.Zip.BadPasswordException)
{
return false;
}
catch (PasswordCheckStream.GoodPasswordException)
{
return true;
}
}
private class PasswordCheckStream : System.IO.MemoryStream
{
public override void Write(byte[] buffer, int offset, int count)
{
throw new GoodPasswordException();
}
public class GoodPasswordException : System.Exception { }
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.