The RasSetEntryProperties function will modify or create a new dial-up networking entry.
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
This following sample function demonstrates using RASSetEntryProperties .
To use it, you would declare a use variable of type VBRasEntry
and pass it to the function. The function returns a long which is 0 is
successful. If unsuccessful use the VBRasErrorHandler
function to get the error string
Dim clsVBRasEntry as VBRasEntry
Dim rtn as long
rtn = VBRasSetEntryProperties("MyConnection", clsVBRasEntry)
If rtn <> 0 then MsgBox VBRASErrorHandler(rtn)
To successfully create a new entry, you will probably have to declare some of it's parameters such as Options, LocalPhoneNumber, DeviceName, DeviceType, fNetProtocols, and/or FramingProtocol.
On NT you can also use the strPhoneBook variable to specify the full path and file name of a phonebook to use. If not specified, the default phonebook is used.
Note: you will need to get the type declaration for VBRasEntry structure from the RasEntry page as it is not included here. Also there is a helper procedure that is used, called CopyStringToByte, which has been included at the bottom of this page.
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" _
(Destination As Any, Source As Any, ByVal Length As Long)
'_____________________________________________________________________
Function VBRasSetEntryProperties(strEntryName As String, _
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 = rtn
End 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
See Also: Contents, Introduction, RasEntry, RasGetEntryProperties, RasEnumDevices, RasCountryInfo, RasErrorHandler.