/**********************************************
* *函 数 名:GetWinZipPath
* *功能描述:读取注册表取得WinZip的安装路径
* *输入参数:无
* *输出参数:WinZip安装路径
* *返 回 值:bool型
* *创 建 人:zifan
* *创建日期:2008-7-7
**********************************************/
public bool GetWinZipPath()
{
try
{
RegistryKey WinZip = Registry.LocalMachine;
RegistryKey SoftWare = WinZip.OpenSubKey("SOFTWARE");
RegistryKey Nico = SoftWare.OpenSubKey("Nico Mak Computing");
RegistryKey ZipPath = Nico.OpenSubKey("WinZip");
RegistryKey Pro = ZipPath.OpenSubKey("Programs");
string Zip = (String)Pro.GetValue("zip2exe", "False");
return true;
}
catch (Exception ex)
{
UserLog.WriteErrorLog("GetWinZipPath" + ex.Message);
return false;
}
}
/**********************************************
* *函 数 名:GetWinRarPath
* *功能描述:读取注册表取得WinRar的安装路径
* *输入参数:无
* *输出参数:WinRar安装路径
* *返 回 值:bool型
* *创 建 人:zifan
* *创建日期:2008-7-22
**********************************************/
public bool GetWinRarPath()
{
try
{
//"Software/Microsoft/Windows/CurrentVersion/App Paths/winrar.EXE", //也可以,更方便
RegistryKey MyReg = Registry.ClassesRoot.OpenSubKey("WinRAR//shell//open//command");
Object MyObj = MyReg.GetValue("");
String MyRar = MyObj.ToString();
MyReg.Close();
MyRar = MyRar.Substring(1, MyRar.Length - 7); //"C:/Program Files/WinRAR/WinRAR.exe" "%1"
if (!File.Exists(MyRar))
{
return false;
}
return true;
}
catch (Exception ex)
{
UserLog.WriteErrorLog("GetWinRarPath" + ex.Message);
return false;
}
}
/**********************************************
* *函 数 名:Rar_UnCompress
* *功能描述:解压缩
* *输入参数:HouPath是解压后路径,RarNameAndPath是rar文件名(包括拓展名)
* *输出参数:是否成功
* *返 回 值:Bool型
* *作 者:zifan
* *日 期:2008-7-22
**********************************************/
public bool Rar_UnCompress(string RarNameAndPath, string HouPath)
{
//RegistryKey MyReg = Registry.ClassesRoot.OpenSubKey("WinRAR//shell//open//command");
RegistryKey MyReg = Registry.LocalMachine.OpenSubKey("Software//Microsoft//Windows//CurrentVersion//App Paths//winrar.EXE");
Object MyObj = MyReg.GetValue("");
String MyRarPath = MyObj.ToString();
MyReg.Close();
//MyRarPath = MyRarPath.Substring(1, MyRarPath.Length - 7);
String Exec = " X /"" + RarNameAndPath + "/" /"" + HouPath+"/"";
Process pro = new Process();
pro.StartInfo.FileName = MyRarPath;
pro.StartInfo.Arguments = Exec;
//pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
try
{
pro.Start();
pro.WaitForExit();
pro.Close();
}
catch (Exception ex)
{
UserLog.WriteErrorLog("Rar_UnCompress:" + ex.Message);
return false;
}
return true;
}
/**********************************************
* *函 数 名:Zip_Compress
* *功能描述:压缩文件
* *输入参数:WinZip32.exe不包括路径,压缩后文件名,要压缩文件名
* *输出参数:是否成功
* *返 回 值:Bool型;
* *作 者:zifan
* *日 期:2008-7-18
**********************************************/
public bool Zip_Compress(string Exe,string NewName,string OldName)
{
string Exec =" -min -a -r -es /"" + NewName + "/" /"" + OldName +"/"";
Process pro = new Process();
pro.StartInfo.FileName = Exe;
pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
pro.StartInfo.Arguments = Exec;
try
{
pro.Start();
pro.WaitForExit();
pro.Close();
}
catch
{
return false;
}
return true;
}
/**********************************************
* *函 数 名:Zip_UnCompress
* *功能描述:解压缩
* *输入参数:WinZip32.exe不包括路径, HouPath是解压后路径,zipname是Zip文件名(不包括拓展名包括路径)
* *输出参数:是否成功
* *返 回 值:Bool型
* *作 者:zifan
* *日 期:2008-7-18
**********************************************/
public bool Zip_UnCompress(string Exe, string HouPath, string zipname)
{
string Exec = " -min -e /"" + zipname + "/" /"" + HouPath + "/"";
Process pro = new Process();
pro.StartInfo.FileName = Exe;
pro.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
pro.StartInfo.Arguments = Exec;
try
{
pro.Start();
pro.WaitForExit();
pro.Close();
}
catch (Exception ex)
{
UserLog.WriteErrorLog("Zip_UnCompress:" + ex.Message);
return false;
}
return true;
}
/**********************************************
* *函 数 名:SFX
* *功能描述:自解压
* *输入参数:Exe_Name,SFX文件全名包括拓展名;exe_Path,SFX文件路径
* *输出参数:是否成功
* *返 回 值:Bool型
* *作 者:zifan
* *日 期:2008-7-18
* *注 释:自解压到同级目录
**********************************************/
public bool SFX_UnCompress(string Exe_Name, string exe_Path)
{
Process pro = new Process();
pro.StartInfo.FileName = Exe_Name;
pro.StartInfo.WorkingDirectory = exe_Path;
pro.StartInfo.CreateNoWindow = true;
pro.StartInfo.Arguments = "/s";//隐藏弹出
try
{
pro.Start();
pro.WaitForExit();
pro.Close();
}
catch (Exception ex)
{
UserLog.WriteErrorLog(ex.Message);
return false;
}
return true;
}
/**********************************************
* *函 数 名:CallExe
* *功能描述:调用可执行文件
* *输入参数:SKEP.UpdateTools.exe,
* *输出参数:是否成功
* *返 回 值:Bool型;
* *作 者:zifan
* *日 期:2008-7-7
**********************************************/
public bool CallExe(string Exe_Name, string exe_Path)
{
Process pro = new Process();
pro.StartInfo.FileName = Exe_Name;
pro.StartInfo.WorkingDirectory = exe_Path;
pro.StartInfo.CreateNoWindow = true;
try
{
pro.Start();
pro.WaitForExit();
pro.Close();
}
catch (Exception ex)
{
UserLog.WriteErrorLog("CallExe:"+ex.Message);
return false;
}
return true;
}