程序执行无报错....但是就是出不来VPN连接...
代码也检查过了 .... 没有拼写错误...
dim $vbNullString=Chr(0)
$Str_RASENTRY = "dword dwSize;dword dwfOptions;dword dwCountryID;dword dwCountryCode;char szLocalPhoneNumber[128];" & _
"dword dwfNetProtocols;dword dwFramingProtocol;" & _
"char szDeviceType[16];char szDeviceName[128];" & _
"dword dwDialMode;dword dwDialExtraPercent;dword dwDialExtraSampleSeconds;dword dwHangUpExtraPercent;" & _
"dword dwHangUpExtraSampleSeconds;dword dwType;dword dwEncryptionType;" & _
"dword dwVpnStrategy;dword dwfOptions2;" & _
"dword dwRedialCount;dword dwRedialPause"
$DLL_RASENTRY = DllStructCreate($Str_RASENTRY)
$Str_RASCREDENTIALS = "dword dwSize;dword dwMask;char szUserName[256];char szPassword[256];char szDomain[15]"
$DLL_RASCREDENTIALS=DllStructCreate($Str_RASCREDENTIALS)
If Create_VPN_Connection("myvpn","vpn1.fast.com","joseya","elitemt0") = True Then
MsgBox(0,0,"Sucessed")
Else
MsgBox(0,0,"Failed")
EndIf
Func Create_VPN_Connection($sEntryName,$sServer,$sUsername,$sPassword)
$Create_VPN_Connection = False
$sDeviceName = "WAN MINIPORT (L2TP)"
$sDeviceType = "vpn"
$size = DllStructGetSize($DLL_RASENTRY)
DllStructSetData($DLL_RASENTRY,"dwSize",$size)
DllStructSetData($DLL_RASENTRY,"dwCountryCode",86)
DllStructSetData($DLL_RASENTRY,"dwCountryID",86)
DllStructSetData($DLL_RASENTRY,"dwDialExtraPercent",75)
DllStructSetData($DLL_RASENTRY,"dwDialExtraSampleSeconds",120)
DllStructSetData($DLL_RASENTRY,"dwDialMode",1)
DllStructSetData($DLL_RASENTRY,"dwfNetProtocols",4)
DllStructSetData($DLL_RASENTRY,"dwfOptions",1024262928)
DllStructSetData($DLL_RASENTRY,"dwfOptions2",367)
DllStructSetData($DLL_RASENTRY,"dwFramingProtocol",1)
DllStructSetData($DLL_RASENTRY,"dwHangUpExtraPercent",10)
DllStructSetData($DLL_RASENTRY,"dwHangUpExtraSampleSeconds",120)
DllStructSetData($DLL_RASENTRY,"dwRedialCount",3)
DllStructSetData($DLL_RASENTRY,"dwRedialPause",60)
DllStructSetData($DLL_RASENTRY,"dwType",5)
CopyMemory("szDeviceName",$sDeviceName,StringLen($sDeviceName))
CopyMemory("szDeviceType",$sDeviceType,StringLen($sDeviceType))
CopyMemory("szLocalPhoneNumber",$sServer,StringLen($sServer))
DllStructSetData($DLL_RASENTRY,"dwVpnStrategy","VS_Default")
DllStructSetData($DLL_RASENTRY,"dwEncryptionType","ET_Optional")
DllStructSetData($DLL_RASCREDENTIALS,"dwSize",DllStructGetSize($DLL_RASCREDENTIALS))
DllStructSetData($DLL_RASCREDENTIALS,"dwMask",11)
CopyMemory("szUserName",$sUsername,StringLen($sUsername))
CopyMemory("szPassword",$sPassword,StringLen($sPassword))
DllCall("rasapi32.dll","dword","RasSetEntryProperties","str",$vbNullString,"str",$sEntryName,"dword*",$DLL_RASENTRY,"dword",$size,"byte",$vbNullString,"dword",0)
If @error = 0 Then
DllCall("rasapi32.dll","dword","RasSetCredentials","str",$vbNullString,"str",$sEntryName,"dword*",$DLL_RASCREDENTIALS,"int",0)
If @error = 0 Then
$Create_VPN_Connection = True
EndIf
EndIf
Return $Create_VPN_Connection
EndFunc
Func CopyMemory($Destination, $Source, $Length)
Local $Return
$Return = DllCall("kernel32.dll", "none", "RtlMoveMemory", "ptr", $Destination, "ptr", $Source,"int", $Length)
Return $Return[0]
EndFunc ;==>CopyMemory
|