问题描述
- VPN宽带连接的时候怎么获取他的错误代码。。比如VPN连接错误代码691,678。。之类的
- using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using DotRas;
using System.Text.RegularExpressions;
namespace VpnTest
{
public class VPNHelper
{
// 系统路径 C:windowssystem32
private static string WinDir = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"""";
// rasdial.exe
private static string RasDialFileName = ""rasdial.exe"";
// VPN路径 C:windowssystem32rasdial.exe
private static string VPNPROCESS = WinDir + RasDialFileName;
// VPN地址
public string IPToPing { get; set; }
// VPN名称
public string VPNName { get; set; }
// VPN用户名
public string UserName { get; set; }
// VPN密码
public string PassWord { get; set; }
public VPNHelper()
{
}
public VPNHelper(string _vpnIP string _vpnName string _userName string _passWord)
{
this.IPToPing = _vpnIP;
this.VPNName = _vpnName;
this.UserName = _userName;
this.PassWord = _passWord;
}
//尝试连接VPN(默认VPN)
public void TryConnectVPN()
{
this.TryConnectVPN(this.VPNNamethis.UserNamethis.PassWord);
}
//尝试断开连接(默认VPN)
public void TryDisConnectVPN()
{
this.TryDisConnectVPN(this.VPNName);
}
//创建或更新一个默认的VPN连接
public void CreateOrUpdateVPN()
{
this.CreateOrUpdateVPN(this.VPNName this.IPToPing);
}
//尝试删除连接(默认VPN)
public void TryDeleteVPN()
{
this.TryDeleteVPN(this.VPNName);
}
//尝试连接VPN(指定VPN名称,用户名,密码)
public void TryConnectVPN(string connVpnNamestring connUserNamestring connPassWord)
{
try
{
string args = string.Format(""{0} {1} {2}"" connVpnName connUserName connUserName);
ProcessStartInfo myProcess = new ProcessStartInfo(VPNPROCESS args);
myProcess.CreateNoWindow = true;
myProcess.UseShellExecute = false;
Process.Start(myProcess);
}
catch (Exception Ex)
{
Debug.Assert(false Ex.ToString());
}
}
//尝试断开VPN(指定VPN名称)
public void TryDisConnectVPN(string disConnVpnName)
{
try
{
string args = string.Format(@""{0} /d"" disConnVpnName);
ProcessStartInfo myProcess = new ProcessStartInfo(VPNPROCESS args);
myProcess.CreateNoWindow = true;
myProcess.UseShellExecute = false;
Process.Start(myProcess);
} catch (Exception Ex) { Debug.Assert(false Ex.ToString()); } }
}
解决方案
好像是因为那个DotRas.dll没有返回报错机制
我最后使用CMD调用rasdial.exe
rasdial connVpnName connUserName connPassWord
解决方案二:
路过帮顶,好像是isp
解决方案三:
691 和 678 都是拨号登录的错误代码
你最好检查下vpn的帐号和密码是否有误