自动连接VPN
来源:互联网 发布:mazak数控车床编程 编辑:程序博客网 时间:2024/06/07 16:14
工作需要,要弄一个自动登录VPN的小程序,网上找了一些方法,这里记录一下。
参数说明:
wzIP VPN服务器的IP
wzEntryName 客户端指定的一个目标名,用户自己随意指定
wzUserName VPN登录用户名
wzPassWord VPN登录密码
DWORD ConnectVPN(const wchar_t *wzIP,const wchar_t *wzEntryName,const wchar_t *wzUserName,const wchar_t *wzPassWord){DWORD dwRet = NO_ERROR;RASENTRYW theRasEntry = {0};下面这一堆参数基本都是写死的,照抄即可theRasEntry.dwType = 2;theRasEntry.dwDialMode = 1;theRasEntry.dwChannels = 0;theRasEntry.dwFrameSize= 0;theRasEntry.dwReserved1 = 0;theRasEntry.dwReserved2 = 0;theRasEntry.dwCountryID = 86;theRasEntry.dwVpnStrategy = 0;theRasEntry.dwRedialCount = 3;theRasEntry.dwfOptions2 = 367;theRasEntry.dwRedialPause = 60;theRasEntry.dwCountryCode = 86;theRasEntry.dwfNetProtocols = 4;theRasEntry.dwEncryptionType = 3;theRasEntry.dwFramingProtocol = 1;theRasEntry.dwfOptions = 1024262928;theRasEntry.dwDialExtraPercent = 75;theRasEntry.dwHangUpExtraPercent = 10;theRasEntry.dwDialExtraSampleSeconds = 120;theRasEntry.dwHangUpExtraSampleSeconds = 120;theRasEntry.dwfNetProtocols= RASNP_Ip;theRasEntry.dwFramingProtocol = RASFP_Ppp;theRasEntry.dwSize = sizeof(theRasEntry);lstrcpyW(theRasEntry.szDeviceName,L"WAN 微型端口 (L2TP)");lstrcpyW(theRasEntry.szDeviceType,L"Vpn");lstrcpyW(theRasEntry.szLocalPhoneNumber,wzIP);//创建目标名dwRet = RasSetEntryPropertiesW(NULL,wzEntryName,&theRasEntry,theRasEntry.dwSize,0,0);if (ERROR_SUCCESS != dwRet){return dwRet;} RASCREDENTIALSW theRascredentials = {0};theRascredentials.dwMask = 11;lstrcpyW(theRascredentials.szUserName,wzUserName);lstrcpyW(theRascredentials.szPassword,wzPassWord);theRascredentials.dwSize = sizeof(theRascredentials);//用户密码保存dwRet = RasSetCredentialsW(NULL,wzEntryName,&theRascredentials,FALSE);if (ERROR_SUCCESS != dwRet){return dwRet;}RASDIALPARAMSW theRasDialParams = {0};lstrcpyW(theRasDialParams.szUserName,wzUserName);lstrcpyW(theRasDialParams.szPassword,wzPassWord);lstrcpyW(theRasDialParams.szEntryName,wzEntryName);theRasDialParams.dwSize = sizeof(theRasDialParams);//开始连接vpnHRASCONN hRasConn = NULL;dwRet = RasDialW(NULL,NULL,&theRasDialParams,0,NULL,&hRasConn);if (ERROR_SUCCESS != dwRet){return dwRet;}return NO_ERROR;}
- 自动连接VPN
- 自动连接VPN
- 自动创建并连接VPN
- UBUNTU自动连接VPN脚本
- Ubuntu 下 VPN 自动连接
- win7下对VPN进行自动连接
- Ubuntu命令行连接VPN并自动设置所有流量通过VPN(通过VPN上网)
- vpn连接
- VPN连接
- VPN连接
- Ubuntu连接VPN的自动重连脚本
- [Windows]开机启动自动连接VPN或ADSL
- ubuntu14.04 vpn自动重新连接 Error: Connection activation failed: no valid VPN secrets 问题解决方法
- VPN连接:win7下建立VPN连接
- VPN连接:win7下建立VPN连接
- Ubuntu下连接VPN!
- vpn连接配置
- 代码实现VPN连接
- wxPython的事件处理
- Redis系列-存储篇sorted set主要操作函数小结
- Android中SQLite应用详解
- ubuntu-12.10-desktop-i386安装注意事项(备忘录)
- 互联网时代的时间管理实践
- 自动连接VPN
- Could not initialize class org.eclipse.jface.preference.PreferenceConverter
- 用C自己编写telnet服务器
- memory:arm 分区layout以及虚拟内存布局-小结
- C标准库
- 无意中发现一个js网站,先记录下来,有空再研究
- 枚举类型
- CentOS 6.2 上编译安装 Nginx 1.0.15 + PHP 5.3.16 + MySQL 5.1.62
- makefile