找回密码
 加入
搜索
查看: 5806|回复: 9

AU3 建立VPN 调用DLL

[复制链接]
发表于 2009-3-28 15:48:59 | 显示全部楼层 |阅读模式
程序执行无报错....但是就是出不来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
发表于 2009-3-28 16:06:27 | 显示全部楼层
...咳咳...我从来没有成功用过这个api...

= = 我有一个dll...是建立vpn使的...


DllCall("dllTest.dll", "none", "createConn", "str", "vpn测试", "str", "127.0.0.1")


很乱... 我只能...做到这里了- -+

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2009-3-28 16:09:46 | 显示全部楼层
话说 能否在一个DLL里面 把 用户名 密码 拨号IP(域名) 都加进去?
 楼主| 发表于 2009-3-28 16:10:34 | 显示全部楼层
and  你的编译环境是什么??
vc 6.0 还是 vs 2003 2005 2008 ?
发表于 2009-3-28 16:18:43 | 显示全部楼层
厉害,非常厉害/.
发表于 2009-3-28 17:08:52 | 显示全部楼层
无报错是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-29 23:16:15 | 显示全部楼层
原帖由 真会走路的废柴 于 2009-3-28 16:10 发表
and  你的编译环境是什么??
vc 6.0 还是 vs 2003 2005 2008 ?

拨号时候加上帐号密码吧...

编译环境vc6
 楼主| 发表于 2009-3-31 11:29:17 | 显示全部楼层
放弃了...

于是用AU3去调用吧

T.T
发表于 2009-3-31 13:03:28 | 显示全部楼层
高手...看不懂...
发表于 2010-7-11 06:02:28 | 显示全部楼层
挖一下坟,我也在这问题上纠结上了.
查了一下,好像说先要用RasGetEntryProperties来获取缓冲结构的大小,不然的话就会返回632,即结构大小不对。
不过RasGetEntryProperties我却找不到调用的例子,希望后来者能研究出来.
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-15 07:23 , Processed in 0.079078 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表