AU3 建立VPN 调用DLL
程序执行无报错....但是就是出不来VPN连接...代码也检查过了 .... 没有拼写错误...
dim $vbNullString=Chr(0)
$Str_RASENTRY = "dword dwSize;dword dwfOptions;dword dwCountryID;dword dwCountryCode;char szLocalPhoneNumber;" & _
"dword dwfNetProtocols;dword dwFramingProtocol;" & _
"char szDeviceType;char szDeviceName;" & _
"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;char szPassword;char szDomain"
$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
EndFunc ;==>CopyMemory ...咳咳...我从来没有成功用过这个api...
= = 我有一个dll...是建立vpn使的...
DllCall("dllTest.dll", "none", "createConn", "str", "vpn测试", "str", "127.0.0.1")
很乱... 我只能...做到这里了- -+ 话说 能否在一个DLL里面 把 用户名 密码 拨号IP(域名) 都加进去? and你的编译环境是什么??
vc 6.0 还是 vs 2003 2005 2008 ? 厉害,非常厉害/. 无报错是DLLCALL这个函数无执行错误,并不代表RasSetEntryProperties的返回值~
把代码DllCall("rasapi32.dll","dword","RasSetEntryProperties","str",$vbNullString,"str",$sEntryName,"dword*",$DLL_RASENTRY,"dword",$size,"byte",$vbNullString,"dword",0)改成$result=DllCall("rasapi32.dll","dword","RasSetEntryProperties","str",$vbNullString,"str",$sEntryName,"dword*",$DLL_RASENTRY,"dword",$size,"byte",$vbNullString,"dword",0)看下result的值,如果是0就执行成功,这是Ras函数库中函数的返回值:http://msdn.microsoft.com/en-us/library/bb530704(VS.85).aspx 原帖由 真会走路的废柴 于 2009-3-28 16:10 发表 http://www.autoitx.com/images/common/back.gif
and你的编译环境是什么??
vc 6.0 还是 vs 2003 2005 2008 ?
拨号时候加上帐号密码吧...
编译环境vc6 放弃了...
于是用AU3去调用吧
T.T 高手...看不懂... 挖一下坟,我也在这问题上纠结上了.
查了一下,好像说先要用RasGetEntryProperties来获取缓冲结构的大小,不然的话就会返回632,即结构大小不对。
不过RasGetEntryProperties我却找不到调用的例子,希望后来者能研究出来.
页:
[1]