vfp9拨号连接怎么做
2个回答
展开全部
vfp创建VPN拨号连接
创建VPN拨号连接*-----------------------------------------------
* VPN 连接测试
*-----------------------------------------------
Local m.lnRasHandle, m.lcErrorStr, m.lnDisCount, m.lcDeviceType
Local m.lcEntryName, m.lcPhoneNumber, m.lcUserName, m.lcPassword
*-----------------------------------------------
* 创建拨号连接
*-----------------------------------------------
m.lcErrorStr = ""
m.lcEntryName = "★★★"
m.lcDeviceType = "vpn"
If Ras_CreateEntry( m.lcEntryName, m.lcDeviceType, @lcErrorStr )
= Messagebox("已经创建: "+m.lcEntryName, 0+64+0, "提示信息")
Else
= Messagebox(m.lcErrorStr, 0+16+0, "创建: "+m.lcEntryName+" 失败!")
Return .F.
Endif
*-----------------------------------------------
* 连接VPN 测试
*-----------------------------------------------
m.lcPhoneNumber = "61.142.173.215"
m.lcUserName = "huangyu"
m.lcPassword = "huangyuhehe"
m.lnDisCount = 0
m.lnRasHandle = 0
m.lcErrorStr = ""
m.lnRasHandle = Ras_Connect( m.lcEntryName, m.lcPhoneNumber, m.lcUserName, m.lcPassword, @lcErrorStr )
If m.lnRasHandle > 0
* 连接成功
= Messagebox("已经连接: "+m.lcEntryName, 0+64+0, "提示信息")
If Ras_DisConn( m.lnRasHandle, @lcErrorStr )
* 断开成功
= Messagebox("已经断开: "+m.lcEntryName, 0+64+0, "提示信息")
Else
* 断开失败
= Messagebox(m.lcErrorStr, 0+16+0, "断开: "+m.lcEntryName+" 失败!")
* 尝试断开所有连接
m.lnDisCount = Ras_DisConn_All( @lcErrorStr )
If m.lnDisCount > 0
* 断开所有连接成功
= Messagebox("已经断开: "+Alltrim(Str(m.lnDisCount))+" 个连接", 0+64+0, "提示信息")
Else
* 断开所有连接失败
= Messagebox(m.lcErrorStr, 0+16+0, "断开: 所有连接 失败!")
Endif
Endif
Else
* 连接失败
= Messagebox(m.lcErrorStr, 0+16+0, "连接: "+m.lcEntryName+" 失败!")
Endif
*-----------------------------------------------
* 删除拨号连接
*-----------------------------------------------
m.lcErrorStr = ""
If Ras_DeleteEntry( m.lcEntryName, @lcErrorStr )
= Messagebox("已经删除: "+m.lcEntryName, 0+64+0, "提示信息")
Else
= Messagebox(m.lcErrorStr, 0+16+0, "删除: "+m.lcEntryName+" 失败!")
Endif
*-----------------------------------------------
Return
*===============================================
* 拨号连接函数库
*===============================================
*-----------------------------------------------
* 函数: Ras_Connect
* 功能: 建立拨号网络连接
* 参数: tcEntryName C, 名称
* tcPhoneNumber C, 地址
* tcUserName C, 用户
* tcPassword C, 密码
* 返回: tnRasHandle I, 连接句柄, 0 失败
* 设计: 红雨
* 时间: 2005.12.18
*-----------------------------------------------
Function Ras_Connect( tcEntryName, tcPhoneNumber, tcUserName, tcPassword, tcErrorStr )
Local m.lcRASDialParams
m.tcErrorStr = ""
m.lcRASDialParams = Chr(28)+Chr(4)+Chr(0)+Chr(0) ;
+ Padr(m.tcEntryName, 256, Chr(0)) + Chr(0) ;
+ Padr(m.tcPhoneNumber, 128, Chr(0)) + Chr(0) ;
+ Padr("", 128, Chr(0)) + Chr(0) ;
+ Padr(m.tcUserName, 256, Chr(0)) + Chr(0) ;
+ Padr(m.tcPassword, 256, Chr(0)) + Chr(0) ;
+ Padr("", 15, Chr(0)) + Chr(0) ;
+ Chr(0) ;
+ Chr(0)
Declare Integer RasDial In RasAPI32.Dll ;
String lpRasDialExtensions, ;
String lpszPhonebook, ;
String lpRASDialParams, ;
Integer dwNotifierType, ;
Integer lpvNotifier, ;
Integer @lphRasConn
Local m.lnHandle, m.lnRetval
m.lnHandle = 0
m.lnRetval = RasDial( Null, Null, @lcRASDialParams, 0, 0, @lnHandle)
If m.lnRetval # 0
m.tcErrorStr = Ras_GetError( m.lnRetval )
Return 0
Else
Return m.lnHandle
Endif
Endfunc
*-----------------------------------------------
* 函数: Ras_DisConn
* 功能: 断开拨号网络连接
* 参数: tnRasHandle I, 连接句柄
* 返回: IsHangUp L, 是否成功
* 设计: 红雨
* 时间: 2005.12.18
*-----------------------------------------------
Function Ras_DisConn( tnRasHandle, tcErrorStr )
Local m.lnRetval
m.lnRetval = -1
m.tcErrorStr = ""
If Type("m.tnRasHandle")="N"
If m.tnRasHandle > 0
Declare Integer RasHangUp In RasAPI32.Dll Integer hRasHandle
m.lnRetval = RasHangUp( m.tnRasHandle )
If m.lnRetval # 0
m.tcErrorStr = Ras_GetError( m.lnRetval )
Endif
Else
m.lnRetval = Iif(Ras_DisConn_All( @tcErrorStr )>0 And Empty(m.tcErrorStr), 0, -1)
Endif
Else
m.tcErrorStr = "句柄参数错误!"
Endif
Return m.lnRetval = 0
Endfunc
*-----------------------------------------------
* 函数: Ras_DisConn_All
* 功能: 断开所有拨号网络连接
* 参数: tcErrorStr C, 错误信息
* 返回: tnReturn I, 断开的连接数
* 设计: 红雨
* 时间: 2005.12.18
*-----------------------------------------------
Function Ras_DisConn_All( tcErrorStr )
m.tcErrorStr = ""
Declare Integer RasHangUp In RasAPI32.Dll ;
Integer hRAsconn
Declare Integer RasEnumConnections In RasApi32.Dll ;
String @lpRAsconn, ;
Integer @lpCb, ;
Integer @lpcConnections
Local m.lnReturn, m.lpRAsconn, m.lpCb, m.lpcConnections
Local m.lngRetCode, m.intLooper, m.lcRAsconn, m.lnRAsconn
m.lnReturn = 0
m.lpRAsconn = Replicate( Ras_DisConn_All_Num2Dword(412) + Ras_DisConn_All_Num2Dword(0) + Replicate(Chr(0),404), 256)
m.lpCb = 256 * 412
m.lpcConnections = 0
m.lngRetCode = RasEnumConnections(@lpRAsconn, @lpCb, @lpcConnections)
If m.lngRetCode = 0 Then
If m.lpcConnections > 0 Then
For m.intLooper = 1 To m.lpcConnections
m.lcRAsconn = Substr( lpRAsconn, (m.intLooper-1)*412+1, 412)
m.lnRAsconn = Ras_DisConn_All_Dword2Num(Substr(m.lcRAsconn,5,4))
If RasHangUp(m.lnRAsconn)=0
m.lnReturn = m.lnReturn + 1
Else
m.tcErrorStr = m.tcErrorStr + Chr(13)+Chr(10) ;
+ Alltrim(Str(m.lnRetval)) + ": " + Ras_GetError( m.lnRetval )
Endif
Endfor
Endif
Endif
Return m.lnReturn
Endfunc
*-----------------------------------------------
Function Ras_DisConn_All_Num2Dword( lpnNum )
Declare Integer RtlMoveMemory In kernel32 As RtlCopyDword ;
String @pDestString, ;
Integer @pVoidSource, ;
Integer nLength
lcDword = Space(4)
= RtlCopyDword(@lcDword, Bitor(lpnNum,0), 4)
Return lcDword
Endfunc
*-----------------------------------------------
Function Ras_DisConn_All_Dword2Num( lpcDword )
Declare Integer RtlMoveMemory In kernel32 As RtlCopyNum ;
Integer @DestNumeric, ;
String @pVoidSource, ;
Integer nLength
lnNum = 0
= RtlCopyNum(@lnNum, lpcDword, 8)
Return lnNum
Endfunc
*-----------------------------------------------
* 函数: Ras_CreateEntry
* 功能: 建立一个拨号连接
* 参数: tcEntryName C, 连接名称
* tcErrorStr C, 错误信息
* 返回: IsCreated L, 是否建立
* 设计: 红雨
* 时间: 2005.12.18
*-----------------------------------------------
Function Ras_CreateEntry( tcEntryName, tcDeviceType, tcErrorStr )
Local m.lnRetval, m.lcRASEntryProperties
m.lnRetval = -1
m.tcErrorStr = ""
m.tcDeviceType = Iif(Type("m.tcDeviceType")="C", m.tcDeviceType, "vpn")
If Type("m.tcEntryName")="C" And !Empty(m.tcEntryName)
Declare Integer RasValidateEntryName In RasAPI32.Dll ;
String lpszPhonebook, ;
String lpRasDialName
Declare Integer RasSetEntryProperties In RasAPI32.Dll ;
String lpszPhonebook, ;
String lpszEntry, ;
String @lpRasEntry, ;
Integer @lpdwEntryInfoSize, ;
String @lpbpDeviceInfo, ;
Integer @lpdwDeviceInfoSize
= RasValidateEntryName(Null, m.tcEntryName)
m.lcRASEntryProperties = Chr(232)+Chr(6)+Chr(0)+Chr(0) ;
+ Chr(16)+Chr(29)+Chr(0)+Chr(48) ;
+ Replicate(Chr(0), 964) ;
+ Padr(m.tcDeviceType, 796, Chr(0))
m.lnRetval = RasSetEntryProperties(Null, m.tcEntryName, @lcRASEntryProperties, 1768, Null, 0)
If m.lnRetval # 0
m.tcErrorStr = Ras_GetError( m.lnRetval )
Endif
Else
m.tcErrorStr = "名称参数错误!"
Endif
Return Empty(m.tcErrorStr)
Endfunc
*-----------------------------------------------
* 函数: Ras_DeleteEntry
* 功能: 删除一个拨号连接
* 参数: tcEntryName C, 连接名称
* tcErrorStr C, 错误信息
* 返回: IsDeleted L, 是否删除
* 设计: 红雨
* 时间: 2005.12.18
*-----------------------------------------------
Function Ras_DeleteEntry( tcEntryName, tcErrorStr )
Local m.lnRetval
m.lnRetval = -1
m.tcErrorStr = ""
If Type("m.tcEntryName")="C" And !Empty(m.tcEntryName)
Declare Integer RasDeleteEntry In RasAPI32.Dll ;
String lpszPhonebook, ;
String lpRasDialName
m.lnRetval = RasDeleteEntry(Null, m.tcEntryName)
If m.lnRetval # 0
m.tcErrorStr = Ras_GetError( m.lnRetval )
Endif
Else
m.tcErrorStr = "名称参数错误!"
Endif
Return Empty(m.tcErrorStr)
Endfunc
*-----------------------------------------------
* 函数: Ras_GetError
* 功能: 获取Ras错误信息
* 参数: tnRasRetval I, 错误代码
* 返回: tcErrorStr C, 错误信息
* 设计: 红雨
* 时间: 2005.12.18
*-----------------------------------------------
Function Ras_GetError( tnRasRetval )
Local m.lcErrorStr
m.lcErrorStr = Space(256)
If Type("m.tnRasRetval")="N" And m.tnRasRetval > 0
Declare Integer RasGetErrorString In RasAPI32.Dll ;
Integer lErrVal, ;
String @sErrStr, ;
Integer lBufSize
If !Empty(RasGetErrorString(m.tnRasRetval, @lcErrorStr, Len(m.lcErrorStr)))
m.lcErrorStr = "Ras 未知错误!"
Endif
Endif
Return Alltrim(m.lcErrorStr)
Endfunc
2017-07-03
展开全部
这个就是这样的啊
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询