C# WinRAR解压类

代码
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Threading;

namespace DataService_Client
{
class WinRAR
{
private static Process myprocess = new Process();

public static bool Rar(string sourcePath, string destPath, string lx)
{
Process process
= new System.Diagnostics.Process();
process.StartInfo.FileName
= "Winrar.exe";
process.StartInfo.WindowStyle
= ProcessWindowStyle.Hidden;
process.StartInfo.CreateNoWindow
= false;
string Myinfo = "";

bool flag = false;

try
{
if (lx == "0")
{
Myinfo
= " a -ep \"" + destPath + "\" " + "\"" + sourcePath + "\"";
}
else
{
Myinfo
= " X -o+ " + destPath + " \"" + sourcePath + "\"";
}

process.StartInfo.Arguments
= Myinfo;
process.Start();

Thread.Sleep(
3000);

if (process.HasExited && (process.ExitCode == 0))
{
flag
= true;
}

KillProcess(
"WinRAR");
}
catch (Exception ex)
{
TPCClass.TPCCommonCls.AddErrorMsg(
"Rar", ex.Message, "WinRAR.txt");
}


return flag;
}

private static void KillProcess(string processname)
{
Process[] processesByName
= Process.GetProcessesByName(processname);

foreach (Process process in processesByName)
{
process.Kill();
}
}
}
}

 

posted @ 2010-05-04 18:00  咖啡无眠  阅读(327)  评论(0)    收藏  举报