The RASGetEntryProperties function will return the properties of a RasEntry. From the PlatformSDK, the function is declared as follows:
Public Declare Function RasGetEntryProperties _ Lib "rasapi32.dll" Alias "RasGetEntryPropertiesA" _ (ByVal lpszPhonebook As String, _ ByVal lpszEntry As String, _ lpRasEntry As Any, _ lpdwEntryInfoSize As Long, _ lpbDeviceInfo As Any, _ lpdwDeviceInfoSize As Long) _ As Long
This following sample function demonstrates using RASGetEntryProperties . 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 = VBRasGetEntryProperties("MyConnection", clsVBRasEntry)
If rtn <> 0 then MsgBox VBRASErrorHandler(rtn)
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 CopyByteToTrimmedString, which has been included at the bottom of this page.
Public Declare Function RasGetEntryProperties _ Lib "rasapi32.dll" Alias "RasGetEntryPropertiesA" _ (ByVal lpszPhonebook As String, _ ByVal lpszEntry As String, _ lpRasEntry As Any, _ lpdwEntryInfoSize As Long, _ lpbDeviceInfo As Any, _ lpdwDeviceInfoSize As Long) As Long Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _ (Destination As Any, Source As Any, ByVal Length As Long) '_____________________________________________________________________ Function VBRasGetEntryProperties(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&) rtn = RasGetEntryProperties(strPhoneBook, strEntryName, _ ByVal 0&, lngBuffLen, ByVal 0&, ByVal 0&) If rtn <> 603 Then VBRasGetEntryProperties = rtn: Exit Function ReDim b(lngBuffLen - 1) CopyMemory b(0), lngCb, 4 rtn = RasGetEntryProperties(strPhoneBook, strEntryName, _ b(0), lngBuffLen, ByVal 0&, ByVal 0&) VBRasGetEntryProperties = rtn If rtn <> 0 Then Exit Function CopyMemory clsRasEntry.Options, b(4), 4 CopyMemory clsRasEntry.CountryID, b(8), 4 CopyMemory clsRasEntry.CountryCode, b(12), 4 CopyByteToTrimmedString clsRasEntry.AreaCode, b(16), 11 CopyByteToTrimmedString clsRasEntry.LocalPhoneNumber, b(27), 129 CopyMemory lngPos, b(156), 4 If lngPos <> 0 Then lngStrLen = lngBuffLen - lngPos clsRasEntry.AlternateNumbers = String(lngStrLen, 0) CopyMemory ByVal clsRasEntry.AlternateNumbers, _ b(lngPos), lngStrLen End If CopyMemory clsRasEntry.ipAddr, b(160), 4 CopyMemory clsRasEntry.ipAddrDns, b(164), 4 CopyMemory clsRasEntry.ipAddrDnsAlt, b(168), 4 CopyMemory clsRasEntry.ipAddrWins, b(172), 4 CopyMemory clsRasEntry.ipAddrWinsAlt, b(176), 4 CopyMemory clsRasEntry.FrameSize, b(180), 4 CopyMemory clsRasEntry.fNetProtocols, b(184), 4 CopyMemory clsRasEntry.FramingProtocol, b(188), 4 CopyByteToTrimmedString clsRasEntry.ScriptName, b(192), 260 CopyByteToTrimmedString clsRasEntry.AutodialDll, b(452), 260 CopyByteToTrimmedString clsRasEntry.AutodialFunc, b(712), 260 CopyByteToTrimmedString clsRasEntry.DeviceType, b(972), 17 If lngCb = 1672& Then lngStrLen = 33 Else lngStrLen = 129 CopyByteToTrimmedString clsRasEntry.DeviceName, b(989), lngStrLen lngPos = 989 + lngStrLen CopyByteToTrimmedString clsRasEntry.X25PadType, b(lngPos), 33 lngPos = lngPos + 33 CopyByteToTrimmedString clsRasEntry.X25Address, b(lngPos), 201 lngPos = lngPos + 201 CopyByteToTrimmedString clsRasEntry.X25Facilities, b(lngPos), 201 lngPos = lngPos + 201 CopyByteToTrimmedString clsRasEntry.X25UserData, b(lngPos), 201 lngPos = lngPos + 203 CopyMemory clsRasEntry.Channels, b(lngPos), 4 If lngCb > 1768 Then 'NT4 Enhancements & Win2000 CopyMemory clsRasEntry.NT4En_SubEntries, b(1768), 4 CopyMemory clsRasEntry.NT4En_DialMode, b(1772), 4 CopyMemory clsRasEntry.NT4En_DialExtraPercent, b(1776), 4 CopyMemory clsRasEntry.NT4En_DialExtraSampleSeconds, b(1780), 4 CopyMemory clsRasEntry.NT4En_HangUpExtraPercent, b(1784), 4 CopyMemory clsRasEntry.NT4En_HangUpExtraSampleSeconds, b(1788), 4 CopyMemory clsRasEntry.NT4En_IdleDisconnectSeconds, b(1792), 4 If lngCb > 1796 Then ' Win2000 CopyMemory clsRasEntry.Win2000_Type, b(1796), 4 CopyMemory clsRasEntry.Win2000_EncryptionType, b(1800), 4 CopyMemory clsRasEntry.Win2000_CustomAuthKey, b(1804), 4 CopyMemory clsRasEntry.Win2000_guidId(0), b(1808), 16 CopyByteToTrimmedString _ clsRasEntry.Win2000_CustomDialDll, b(1824), 260 CopyMemory clsRasEntry.Win2000_VpnStrategy, b(2084), 4 End If End If End Function
Sub CopyByteToTrimmedString(strToCopyTo As String, _ bPos As Byte, lngMaxLen As Long) Dim strTemp As String, lngLen As Long strTemp = String(lngMaxLen + 1, 0) CopyMemory ByVal strTemp, bPos, lngMaxLen lngLen = InStr(strTemp, Chr$(0)) - 1 strToCopyTo = Left$(strTemp, lngLen) End Sub
See Also: Contents, Introduction, RasEntry, RasErrorHandler, RasSetEntryProperties.