自动连接VPN
来源:互联网 发布:免费听课的软件 编辑:程序博客网 时间:2024/05/24 02:35
工作需要,要弄一个自动登录VPN的小程序,网上找了一些方法,这里记录一下。
参数说明:
wzIP VPN服务器的IP
wzEntryName 客户端指定的一个目标名,用户自己随意指定
wzUserName VPN登录用户名
wzPassWord VPN登录密码
参数说明:
wzIP VPN服务器的IP
wzEntryName 客户端指定的一个目标名,用户自己随意指定
wzUserName VPN登录用户名
wzPassWord VPN登录密码
- <pre name="code" class="cpp">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);
- //开始连接vpn
- HRASCONN hRasConn = NULL;
- dwRet = RasDialW(NULL,NULL,&theRasDialParams,0,NULL,&hRasConn);
- if (ERROR_SUCCESS != dwRet)
- {
- return dwRet;
- }
- return NO_ERROR;
- }
- </pre><br>
- <br>
- <pre></pre>
- <br>
- <br>
- <br>
- <br>
0 0
- 自动连接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连接
- 深入浅出MFC 第8章 关于序列化(Serialize)的一些问题
- Memory Leak分析分享
- Android的AlertDialog详解
- Lucene
- 教你从零开始成为优秀交互设计师(一):交互设计师修炼指南
- 自动连接VPN
- 字符串处理
- S3C2440 Linux驱动移植——LED heartbeat
- MFC遍历某个文件夹,并用tree Control简单显示
- Labview使用UDP通信的问题
- spring源码阅读(五)之ApplicationContext
- Android系统权限和root权限
- 客户端程序开发中的mvc设计模式
- 【Leetcode】Permutations (Backtracking)