先断开网络连接
/// <summary>
/// 断开网络连接
/// </summary>
public static void Logout()
{
ReadOnlyCollection<RasConnection> conList = RasConnection.GetActiveConnections();
foreach (RasConnection con in conList)
{
con.HangUp();
}
}
重新拨号
/// <summary>
/// 开始拨号
/// </summary>
/// <returns>返回拨号进程的返回值</returns>
public static int Connect()
{
//联网参数
string intername = Common.DESEncrypt.DesDecrypt(Common.MethodClass.GetConfigValue("intername").ToString());
string interpwd = Common.DESEncrypt.DesDecrypt(Common.MethodClass.GetConfigValue("interpwd").ToString()); ProcessWindowStyle _windowstyle = ProcessWindowStyle.Hidden;
Process pro = new Process();
pro.StartInfo.FileName = "rasdial.exe"; //intername宽带用户名,interpwd宽度密码
pro.StartInfo.Arguments = "宽带连接" + " " + intername + " " + interpwd;
pro.StartInfo.WindowStyle = _windowstyle;
pro.Start();
pro.WaitForExit();
return pro.ExitCode;
}
调用
public void buttonItem2_Click(object sender, EventArgs e)
{
Logout();
if (Connect() == )
{
//拨号成功
}
else
{
//拨号失败
}
}