CopyMemory(@szLocalPhoneNumber, ServerIP, lstrlenA(ServerIP)); end; with Rc do begin dwSize := SizeOf(TRasCredentialsA); dwMask := 11; end; CopyMemory(@Rc.szUserName, UserName, lstrlenA(UserName)); CopyMemory(@Rc.szPassword, PassWord, lstrlenA(PassWord)); if RasSetEntryPropertiesA(Nil, VPNName, @Re, SizeOf(TRasEntry), nil, 0) = ERROR_SUCCESS then begin if RasSetCredentialsA(Nil, VPNName, @Rc, 0) = ERROR_SUCCESS then begin Result := True; end; end; end;
Function ConnectVPN(VPNName :PAnsichar):Boolean; stdcall; Var DialParams :TRasDialParams; lpfPassword:LongBool; lpStatus :TRasConnStatusA; begin Result := False; ZeroMemory(@DialParams, SizeOf(TRasDialParams)); with DialParams do begin dwSize := Sizeof(TRasDialParams); lstrcpyA(@szEntryName, VPNName); end; if RasGetEntryDialParamsA(nil, DialParams, lpfPassword) = ERROR_SUCCESS then begin if RasDialA(nil, nil, DialParams, 0, nil, hRasconn) = ERROR_SUCCESS then begin Result := True; if RasGetConnectStatusA(hRasconn, lpStatus) = ERROR_SUCCESS then begin OutputDebugStringA(lpStatus.szDeviceName); OutputDebugStringA(lpStatus.szDeviceType); end; Exit; end; end; if Not Result then RasDeleteEntryA(Nil, VPNName); end;
Function CloseVPN():Boolean; begin Result := True; if hRasconn > 0 then begin Result := RasHangUpA(hRasconn) = ERROR_SUCCESS; //if Result then //RasDeleteEntryA(Nil, VPNName); end; end;
if CreateVPN('VPN_Test', '6.6.6.6', 'vpn_user', '7xCode') then begin if ConnectVPN('VPN_Test') then begin Caption := 'ConnectIng';