class ADSLHelper
{
/// <summary>
///拨号
/// </summary>
/// <param name="connectionName"></param>
/// <param name="user"></param>
/// <param name="pass"></param>
/// <returns></returns>
public string Connect(string connectionName, string user, string pass)
{
string arg = string.Format("rasdial \"{0}\" {1} {2}", connectionName, user, pass);
return InvokeCmd(arg);
}
/// <summary>
/// 断开
/// </summary>
/// <param name="connectionName"></param>
/// <returns></returns>
public string Disconnect(string connectionName)
{
string arg = string.Format("rasdial \"{0}\" /disconnect", connectionName);
return InvokeCmd(arg);
}
public static string InvokeCmd(string cmdArgs)
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.StandardInput.WriteLine(cmdArgs);
p.StandardInput.WriteLine("exit");
return p.StandardOutput.ReadToEnd();
}
}