是用MODEN进行拨号上网,断开。如何使用代码实现,必须在win98 ,win2000下可以用,
以前有一种做法:就是建立一个连接 “我的连接” 然后调用它,但这个东西的问题是
“我的连接”是否拨通,这个状态没办法知道,如何优化?更人性化。
另外还有一个做法:就是直接完全溶到程序中,只要程序输入16388,拨号就进行连接,并会返回状态是最好的,洋鬼子有做过这样的东西,但只可惜(不说大家也知道)
请高手指点一、二。
以前有一种做法:就是建立一个连接 “我的连接” 然后调用它,但这个东西的问题是
“我的连接”是否拨通,这个状态没办法知道,如何优化?更人性化。
另外还有一个做法:就是直接完全溶到程序中,只要程序输入16388,拨号就进行连接,并会返回状态是最好的,洋鬼子有做过这样的东西,但只可惜(不说大家也知道)
请高手指点一、二。
新建拨号连接复杂
以下为新建一个拨号连接:
module:
Option Explicit
'**********************************
'* Constant Declarations *
'**********************************
'constants needed for UDTs
Public Const UNLEN = 256
Public Const DNLEN = 15
Public Const PWLEN = 256Public Const RAS_MaxDeviceType = 16
Public Const RAS_MaxPhoneNumber = 128
Public Const RAS_MaxIpAddress = 15
Public Const RAS_MaxIpxAddress = 21
Public Const RAS_MaxEntryName = 20
Public Const RAS_MaxDeviceName = 32
Public Const RAS_MaxCallbackNumber = 48Public Const RAS95_MaxEntryName = 256
Public Const RAS95_MaxDeviceName = 128
Public Const RAS95_MaxCallbackNumber = RAS_MaxPhoneNumberPublic Type RASDIALPARAMS95
'set dwsize to 1052
dwSize As Long
szEntryName(RAS95_MaxEntryName) As Byte
szPhoneNumber(RAS_MaxPhoneNumber) As Byte
szCallbackNumber(RAS95_MaxCallbackNumber) As Byte
szUserName(UNLEN) As Byte
szPassword(PWLEN) As Byte
szDomain(DNLEN) As Byte
End Type
'**********************************
'* WIN32 Type Declarations *
'**********************************
'We have to determine the OS version
Public Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128 ' Maintenance string for PSS usage
End Type
Public Type RASIPADDR
a As Byte
b As Byte
c As Byte
d As Byte
End TypePublic Enum RasEntryOptions
RASEO_UseCountryAndAreaCodes = &H1
RASEO_SpecificIpAddr = &H2
RASEO_SpecificNameServers = &H4
RASEO_IpHeaderCompression = &H8
RASEO_RemoteDefaultGateway = &H10
RASEO_DisableLcpExtensions = &H20
RASEO_TerminalBeforeDial = &H40
RASEO_TerminalAfterDial = &H80
RASEO_ModemLights = &H100
RASEO_SwCompression = &H200
RASEO_RequireEncryptedPw = &H400
RASEO_RequireMsEncryptedPw = &H800
RASEO_RequireDataEncryption = &H1000
RASEO_NetworkLogon = &H2000
RASEO_UseLogonCredentials = &H4000
RASEO_PromoteAlternates = &H8000
RASEO_SecureLocalFiles = &H10000
RASEO_RequireEAP = &H20000
RASEO_RequirePAP = &H40000
RASEO_RequireSPAP = &H80000
RASEO_Custom = &H100000
RASEO_PreviewPhoneNumber = &H200000
RASEO_SharedPhoneNumbers = &H800000
RASEO_PreviewUserPw = &H1000000
RASEO_PreviewDomain = &H2000000
RASEO_ShowDialingProgress = &H4000000
RASEO_RequireCHAP = &H8000000
RASEO_RequireMsCHAP = &H10000000
RASEO_RequireMsCHAP2 = &H20000000
RASEO_RequireW95MSCHAP = &H40000000
RASEO_CustomScript = &H80000000
End EnumPublic Enum RASNetProtocols
RASNP_NetBEUI = &H1
RASNP_Ipx = &H2
RASNP_Ip = &H4
End EnumPublic Enum RasFramingProtocols
RASFP_Ppp = &H1
RASFP_Slip = &H2
RASFP_Ras = &H4
End EnumPublic Type VBRasEntry
Options As RasEntryOptions
CountryID As Long
CountryCode As Long
AreaCode As String
LocalPhoneNumber As String
AlternateNumbers As String
ipAddr As RASIPADDR
ipAddrDns As RASIPADDR
ipAddrDnsAlt As RASIPADDR
ipAddrWins As RASIPADDR
ipAddrWinsAlt As RASIPADDR
FrameSize As Long
fNetProtocols As RASNetProtocols
FramingProtocol As RasFramingProtocols
ScriptName As String
AutodialDll As String
AutodialFunc As String
DeviceType As String
DeviceName As String
X25PadType As String
X25Address As String
X25Facilities As String
X25UserData As String
Channels As Long
NT4En_SubEntries As Long
NT4En_DialMode As Long
NT4En_DialExtraPercent As Long
NT4En_DialExtraSampleSeconds As Long
NT4En_HangUpExtraPercent As Long
NT4En_HangUpExtraSampleSeconds As Long
NT4En_IdleDisconnectSeconds As Long
Win2000_Type As Long
Win2000_EncryptionType As Long
Win2000_CustomAuthKey As Long
Win2000_guidId(0 To 15) As Byte
Win2000_CustomDialDll As String
Win2000_VpnStrategy As Long
End TypePublic Enum RasProjection
RASP_Amb = &H10000 ' Specifies the Authentication Message Block (AMB) authentication protocol. AMB is a NetBIOS-based protocol used to authenticate with downlevel remote access servers ( all those prior to Windows NT 3.5). The corresponding data structure is a RASAMB.
RASP_PppNbf = &H803F ' Specifies the NetBEUI Framer (NBF) protocol. NBFCP is a PPP network control protocol used to negotiate the parameters necessary to ship NetBEUI packets on a WAN link. The corresponding data structure is a RASPPPNBF.
RASP_PppIpx = &H802B ' Specifies the Internetwork Packet Exchange (IPX) control protocol. IPXCP is a PPP network control protocol used to negotiate the parameters necessary to ship IPX packets on a WAN link. The corresponding data structure is a RASPPPIPX.
RASP_PppIp = &H8021 ' Specifies the Internet Protocol (IP) control protocol. IPCP is a PPP network control protocol used to negotiate the parameters necessary to ship IP packets on a WAN link. The corresponding data structure is a RASPPPIP.
RASP_PppCcp = &H80FD ' Windows 2000: Specifies the Compression Control Protocol (CCP). CCP enables computers using PPP to negotiate compression algorithms and parameters. The corresponding data structure is RASPPPCCP.
RASP_PppLcp = &HC021 ' Windows 2000: Specifies the Link Control Protocol (LCP). LCP is used by computers to establish, modify, and terminate PPP connections. The corresponding data structure is RASPPPLCP.
RASP_Slip = &H20000 ' Windows 2000: Specifies the Serial Line Internet Protocol (SLIP). SLIP is a framing protocol used primarily in UNIX environments.
End Enum
Public Declare Function RasSetEntryProperties Lib "rasapi32.dll" Alias "RasSetEntryPropertiesA" (ByVal lpszPhonebook As String, ByVal lpszEntry As String, lpRasEntry As Any, ByVal dwEntryInfoSize As Long, lpbDeviceInfo As Any, ByVal dwDeviceInfoSize As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
clsRasEntry As VBRasEntry, _
Optional strPhoneBook As String) As Long
Dim rtn As Long, lngCb As Long, lngBuffLen As Long
Dim b() As Byte
Dim lngPos As Long, lngStrLen As Long rtn = RasGetEntryProperties(vbNullString, vbNullString, ByVal 0&, lngCb, ByVal 0&, ByVal 0&) If rtn <> 603 Then VBRasSetEntryProperties = rtn: Exit Function
lngStrLen = Len(clsRasEntry.AlternateNumbers)
lngBuffLen = lngCb + lngStrLen + 1
ReDim b(lngBuffLen)
CopyMemory b(0), lngCb, 4
CopyMemory b(4), clsRasEntry.Options, 4
CopyMemory b(8), clsRasEntry.CountryID, 4
CopyMemory b(12), clsRasEntry.CountryCode, 4
CopyStringToByte b(16), clsRasEntry.AreaCode, 11
CopyStringToByte b(27), clsRasEntry.LocalPhoneNumber, 129
If lngStrLen > 0 Then
CopyMemory b(lngCb), _
ByVal clsRasEntry.AlternateNumbers, lngStrLen
CopyMemory b(156), lngCb, 4
End If CopyMemory b(160), clsRasEntry.ipAddr, 4
CopyMemory b(164), clsRasEntry.ipAddrDns, 4
CopyMemory b(168), clsRasEntry.ipAddrDnsAlt, 4
CopyMemory b(172), clsRasEntry.ipAddrWins, 4
CopyMemory b(176), clsRasEntry.ipAddrWinsAlt, 4
CopyMemory b(180), clsRasEntry.FrameSize, 4
CopyMemory b(184), clsRasEntry.fNetProtocols, 4
CopyMemory b(188), clsRasEntry.FramingProtocol, 4
CopyStringToByte b(192), clsRasEntry.ScriptName, 260
CopyStringToByte b(452), clsRasEntry.AutodialDll, 260
CopyStringToByte b(712), clsRasEntry.AutodialFunc, 260
CopyStringToByte b(972), clsRasEntry.DeviceType, 17
If lngCb = 1672& Then lngStrLen = 33 Else lngStrLen = 129
CopyStringToByte b(989), clsRasEntry.DeviceName, lngStrLen
lngPos = 989 + lngStrLen
CopyStringToByte b(lngPos), clsRasEntry.X25PadType, 33
lngPos = lngPos + 33
CopyStringToByte b(lngPos), clsRasEntry.X25Address, 201
lngPos = lngPos + 201
CopyStringToByte b(lngPos), clsRasEntry.X25Facilities, 201
lngPos = lngPos + 201
CopyStringToByte b(lngPos), clsRasEntry.X25UserData, 201
lngPos = lngPos + 203
CopyMemory b(lngPos), clsRasEntry.Channels, 4
If lngCb > 1768 Then 'NT4 Enhancements & Win2000
CopyMemory b(1768), clsRasEntry.NT4En_SubEntries, 4
CopyMemory b(1772), clsRasEntry.NT4En_DialMode, 4
CopyMemory b(1776), clsRasEntry.NT4En_DialExtraPercent, 4
CopyMemory b(1780), clsRasEntry.NT4En_DialExtraSampleSeconds, 4
CopyMemory b(1784), clsRasEntry.NT4En_HangUpExtraPercent, 4
CopyMemory b(1788), clsRasEntry.NT4En_HangUpExtraSampleSeconds, 4
CopyMemory b(1792), clsRasEntry.NT4En_IdleDisconnectSeconds, 4
If lngCb > 1796 Then ' Win2000
CopyMemory b(1796), clsRasEntry.Win2000_Type, 4
CopyMemory b(1800), clsRasEntry.Win2000_EncryptionType, 4
CopyMemory b(1804), clsRasEntry.Win2000_CustomAuthKey, 4
CopyMemory b(1808), clsRasEntry.Win2000_guidId(0), 16
CopyStringToByte b(1824), clsRasEntry.Win2000_CustomDialDll, 260
CopyMemory b(2084), clsRasEntry.Win2000_VpnStrategy, 4
End If
End If
rtn = RasSetEntryProperties(strPhoneBook, strEntryName, _
b(0), lngCb, ByVal 0&, ByVal 0&)
VBRasSetEntryProperties = rtnEnd Function
Sub CopyStringToByte(bPos As Byte, _
strToCopy As String, lngMaxLen As Long)
Dim lngLen As Long
lngLen = Len(strToCopy)
If lngLen = 0 Then
Exit Sub
ElseIf lngLen > lngMaxLen Then
lngLen = lngMaxLen
End If
CopyMemory bPos, ByVal strToCopy, lngLen
End Sub
Option Explicit
Private hRasConn As Long
Dim lngRetCode As Long
Dim m_RasDialParams As RASDIALPARAMS
Dim clsRasEntry As VBRasEntryPublic Function add(strNewPhonebook As String, strNewEntry As String)
lngRetCode = RasValidateEntryName(vbNullString, strNewEntry)
End Function
Private Sub Form_Load()Dim a As String
clsRasEntry.DeviceName = "xxx Modem"'clsRasEntry.fNetProtocols = RASNP_NetBEUI
'clsRasEntry.FramingProtocol = RASFP_Slip
'clsRasEntry.fNetProtocols = RASNP_Ip
'clsRasEntry.fNetProtocols = RASNP_Ipx
'clsRasEntry.FramingProtocol = RASFP_Ras
clsRasEntry.DeviceType = "modem"
clsRasEntry.LocalPhoneNumber = "#777"
clsRasEntry.FramingProtocol = RASFP_Ppp Or RASFP_Ras Or RASFP_Slip
clsRasEntry.fNetProtocols = RASNP_Ip Or RASNP_Ipx Or RASNP_NetBEUI
'clsRasEntry.Options = RASEO_IpHeaderCompression Or RASEO_RemoteDefaultGateway Or RASEO_PreviewUserPw Or RASEO_ModemLights Or RASEO_SecureLocalFiles Or RASEO_PreviewPhoneNumber Or RASEO_IpHeaderCompression Or RASEO_SwCompression
clsRasEntry.Options = RASEO_RemoteDefaultGateway Or RASEO_PreviewUserPw Or RASEO_ModemLights Or RASEO_SecureLocalFiles Or RASEO_PreviewPhoneNumber Or RASEO_IpHeaderCompression Or RASEO_SwCompression 'Or &H400000
' Or RASEO_ShowDialingProgress 'Or RASEO_SharedPhoneNumbers '拨号上网属性设置' Or RASEO_ShowDialingProgress 'Or RASEO_SharedPhoneNumbers
clsRasEntry.Options = &H5A00318lngRetCode = VBRasSetEntryProperties("xxx", clsRasEntry, vbNullString)
Unload Me
End Sub