C# 实现拨号重连

先断开网络连接

 /// <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
{
//拨号失败
}
}

转载请注明出入来源:https://www.cnblogs.com/famhuai/p/10539259.html

上一篇:设置字体格式,加粗,regular,light


下一篇:(系统架构)标准Web系统的架构分层