Home All Groups Group Topic Archive Search About

Get information about Dial Up connections?

Author
20 Jan 2006 12:56 PM
Lars Netzel
Hi

How do I get information (read) about the phonenumber in the default Dial Up
Connection?

Best Regards/
Lars Netzel

Author
20 Jan 2006 7:17 PM
Dragon
Hi Lars,

This code will retrieve phone numbers if given a connection name,
although I unfortunately don't know how to get the default one
currently. Take a look at other RAS (maybe, WinINet) functions.

~
    Friend Declare Auto Function RasGetEntryProperties Lib
"rasapi32.dll" ( _
        <MarshalAs(UnmanagedType.LPTStr)> ByVal lpszPhonebook As String,
_
        <MarshalAs(UnmanagedType.LPTStr)> ByVal lpszEntry As String, _
        ByVal lpRasEntry As IntPtr, _
        ByRef lpdwEntryInfoSize As Integer, _
        ByVal lpbDeviceInfo As IntPtr, _
        ByVal lpdwDeviceInfoSize As IntPtr _
    ) As Integer

    Const RAS_MaxDeviceType As Integer = 16
    Const RAS_MaxPhoneNumber As Integer = 128
    Const RAS_MaxEntryName As Integer = 256
    Const RAS_MaxDeviceName As Integer = 128
    Const RAS_MaxAreaCode As Integer = 10
    Const RAS_MaxPadType As Integer = 32
    Const RAS_MaxX25Address As Integer = 200
    Const RAS_MaxFacilities As Integer = 200
    Const RAS_MaxUserData As Integer = 200
    Const MAX_PATH As Integer = 260

    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> Friend
Structure RASENTRY
        Public dwSize As Integer
        Public dwfOptions As Integer

        Public dwCountryID As Integer
        Public dwCountryCode As Integer
        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxAreaCode +
1)> Public szAreaCode As String
        <MarshalAs(UnmanagedType.ByValTStr,
sizeconst:=RAS_MaxPhoneNumber + 1)> Public szLocalPhoneNumber As String
        Public dwAlternateOffset As Integer

        Public ipaddr As RASIPADDR
        Public ipaddrDns As RASIPADDR
        Public ipaddrDnsAlt As RASIPADDR
        Public ipaddrWins As RASIPADDR
        Public ipaddrWinsAlt As RASIPADDR

        Public dwFrameSize As Integer
        Public dwfNetProtocols As Integer
        Public dwFramingProtocol As Integer

        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=MAX_PATH)> Public
szScript As String

        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=MAX_PATH)> Public
szAutodialDll As String
        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=MAX_PATH)> Public
szAutodialFunc As String

        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxDeviceType
+ 1)> Public szDeviceType As String
        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxDeviceName
+ 1)> Public szDeviceName As String

        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxPadType +
1)> Public szX25PadType As String
        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxX25Address
+ 1)> Public szX25Address As String
        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxFacilities
+ 1)> Public szX25Facilities As String
        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxUserData +
1)> Public szX25UserData As String
        Public dwChannels As Integer

        Public dwReserved1 As Integer
        Public dwReserved2 As Integer

        Public dwSubEntries As Integer
        Public dwDialMode As Integer
        Public dwDialExtraPercent As Integer
        Public dwDialExtraSampleSeconds As Integer
        Public dwHangUpExtraPercent As Integer
        Public dwHangUpExtraSampleSeconds As Integer

        Public dwIdleDisconnectSeconds As Integer
    End Structure
    <StructLayout(LayoutKind.Sequential)> Friend Structure RASIPADDR
        Public a, b, c, d As Byte
    End Structure

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Label1.Click
        Dim MyRasEntry As RASENTRY
        Dim REPtr As IntPtr
        Dim size As Integer = 0
        Dim Res As Integer
        RasGetEntryProperties(Nothing, "<insert connection name here>",
IntPtr.Zero, size, IntPtr.Zero, IntPtr.Zero)
        REPtr = Marshal.AllocHGlobal(size)
        Marshal.WriteInt32(REPtr, Marshal.SizeOf(GetType(RASENTRY)))
        Res = RasGetEntryProperties(Nothing, "<insert connection name
here>", REPtr, size, IntPtr.Zero, IntPtr.Zero)
        If Res <> 0 Then
            MessageBox.Show("Error ¹" & CStr(Res) & " occurred.")
        Else
            MyRasEntry = DirectCast(Marshal.PtrToStructure(REPtr,
GetType(RASENTRY)), RASENTRY)
            MessageBox.Show(MyRasEntry.szLocalPhoneNumber)
            If MyRasEntry.dwAlternateOffset > 0 Then
                Dim CurPhoneAddr As Integer = REPtr.ToInt32 +
MyRasEntry.dwAlternateOffset
                Dim CurPhone As String
                Do Until Marshal.ReadByte(New IntPtr(CurPhoneAddr)) = 0
                    CurPhone = Marshal.PtrToStringAuto(New
IntPtr(CurPhoneAddr))
                    MessageBox.Show(CurPhone)
                    CurPhoneAddr += (CurPhone.Length + 1) *
Marshal.SystemDefaultCharSize
                Loop
            End If
        End If
        Marshal.FreeHGlobal(REPtr)
    End Sub
~

HTH a bit,
Roman
Author
24 Jan 2006 7:26 AM
Lars Netzel
Hi,

Thank you but I can't compile that code.. Getting blue underlines all over
the place. Especially on Marchall words...

Is there anywhere I can read about this more?

/Lars




Show quoteHide quote
"Dragon" <no@spam.please> wrote in message
news:Ogb5mYfHGHA.648@TK2MSFTNGP14.phx.gbl...
> Hi Lars,
>
> This code will retrieve phone numbers if given a connection name,
> although I unfortunately don't know how to get the default one
> currently. Take a look at other RAS (maybe, WinINet) functions.
>
> ~
>    Friend Declare Auto Function RasGetEntryProperties Lib
> "rasapi32.dll" ( _
>        <MarshalAs(UnmanagedType.LPTStr)> ByVal lpszPhonebook As String,
> _
>        <MarshalAs(UnmanagedType.LPTStr)> ByVal lpszEntry As String, _
>        ByVal lpRasEntry As IntPtr, _
>        ByRef lpdwEntryInfoSize As Integer, _
>        ByVal lpbDeviceInfo As IntPtr, _
>        ByVal lpdwDeviceInfoSize As IntPtr _
>    ) As Integer
>
>    Const RAS_MaxDeviceType As Integer = 16
>    Const RAS_MaxPhoneNumber As Integer = 128
>    Const RAS_MaxEntryName As Integer = 256
>    Const RAS_MaxDeviceName As Integer = 128
>    Const RAS_MaxAreaCode As Integer = 10
>    Const RAS_MaxPadType As Integer = 32
>    Const RAS_MaxX25Address As Integer = 200
>    Const RAS_MaxFacilities As Integer = 200
>    Const RAS_MaxUserData As Integer = 200
>    Const MAX_PATH As Integer = 260
>
>    <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> Friend
> Structure RASENTRY
>        Public dwSize As Integer
>        Public dwfOptions As Integer
>
>        Public dwCountryID As Integer
>        Public dwCountryCode As Integer
>        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxAreaCode +
> 1)> Public szAreaCode As String
>        <MarshalAs(UnmanagedType.ByValTStr,
> sizeconst:=RAS_MaxPhoneNumber + 1)> Public szLocalPhoneNumber As String
>        Public dwAlternateOffset As Integer
>
>        Public ipaddr As RASIPADDR
>        Public ipaddrDns As RASIPADDR
>        Public ipaddrDnsAlt As RASIPADDR
>        Public ipaddrWins As RASIPADDR
>        Public ipaddrWinsAlt As RASIPADDR
>
>        Public dwFrameSize As Integer
>        Public dwfNetProtocols As Integer
>        Public dwFramingProtocol As Integer
>
>        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=MAX_PATH)> Public
> szScript As String
>
>        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=MAX_PATH)> Public
> szAutodialDll As String
>        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=MAX_PATH)> Public
> szAutodialFunc As String
>
>        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxDeviceType
> + 1)> Public szDeviceType As String
>        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxDeviceName
> + 1)> Public szDeviceName As String
>
>        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxPadType +
> 1)> Public szX25PadType As String
>        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxX25Address
> + 1)> Public szX25Address As String
>        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxFacilities
> + 1)> Public szX25Facilities As String
>        <MarshalAs(UnmanagedType.ByValTStr, sizeconst:=RAS_MaxUserData +
> 1)> Public szX25UserData As String
>        Public dwChannels As Integer
>
>        Public dwReserved1 As Integer
>        Public dwReserved2 As Integer
>
>        Public dwSubEntries As Integer
>        Public dwDialMode As Integer
>        Public dwDialExtraPercent As Integer
>        Public dwDialExtraSampleSeconds As Integer
>        Public dwHangUpExtraPercent As Integer
>        Public dwHangUpExtraSampleSeconds As Integer
>
>        Public dwIdleDisconnectSeconds As Integer
>    End Structure
>    <StructLayout(LayoutKind.Sequential)> Friend Structure RASIPADDR
>        Public a, b, c, d As Byte
>    End Structure
>
>    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles Label1.Click
>        Dim MyRasEntry As RASENTRY
>        Dim REPtr As IntPtr
>        Dim size As Integer = 0
>        Dim Res As Integer
>        RasGetEntryProperties(Nothing, "<insert connection name here>",
> IntPtr.Zero, size, IntPtr.Zero, IntPtr.Zero)
>        REPtr = Marshal.AllocHGlobal(size)
>        Marshal.WriteInt32(REPtr, Marshal.SizeOf(GetType(RASENTRY)))
>        Res = RasGetEntryProperties(Nothing, "<insert connection name
> here>", REPtr, size, IntPtr.Zero, IntPtr.Zero)
>        If Res <> 0 Then
>            MessageBox.Show("Error ¹" & CStr(Res) & " occurred.")
>        Else
>            MyRasEntry = DirectCast(Marshal.PtrToStructure(REPtr,
> GetType(RASENTRY)), RASENTRY)
>            MessageBox.Show(MyRasEntry.szLocalPhoneNumber)
>            If MyRasEntry.dwAlternateOffset > 0 Then
>                Dim CurPhoneAddr As Integer = REPtr.ToInt32 +
> MyRasEntry.dwAlternateOffset
>                Dim CurPhone As String
>                Do Until Marshal.ReadByte(New IntPtr(CurPhoneAddr)) = 0
>                    CurPhone = Marshal.PtrToStringAuto(New
> IntPtr(CurPhoneAddr))
>                    MessageBox.Show(CurPhone)
>                    CurPhoneAddr += (CurPhone.Length + 1) *
> Marshal.SystemDefaultCharSize
>                Loop
>            End If
>        End If
>        Marshal.FreeHGlobal(REPtr)
>    End Sub
> ~
>
> HTH a bit,
> Roman
>
>
Author
24 Jan 2006 10:37 AM
Armin Zingler
"Lars Netzel" <uih***@adf.se> schrieb
> Hi,
>
> Thank you but I can't compile that code.. Getting blue underlines
> all over the place. Especially on Marchall words...


Is it so hard find that Marshal is part of the
System.Runtime.InteropServices namespace? Just wondering.


Add

    Imports System.Runtime.InteropServices

at the top of the file.


Armin
Author
24 Jan 2006 12:28 PM
Lars Netzel
For me yes.. I don't know ANYTHING about APIs really so.. struct and <>
signs and Auto declares are a bit off for me.. BUT,, it doesn't matter.. I
just found that the Dial Up connections are saved in a separate textfile
this turned out to be easier to read thru the System.IO.File way... so..

Thanx anyway...
/Lars


Show quoteHide quote
"Armin Zingler" <az.nospam@freenet.de> wrote in message
news:eM76lQNIGHA.1032@TK2MSFTNGP11.phx.gbl...
> "Lars Netzel" <uih***@adf.se> schrieb
>> Hi,
>>
>> Thank you but I can't compile that code.. Getting blue underlines
>> all over the place. Especially on Marchall words...
>
>
> Is it so hard find that Marshal is part of the
> System.Runtime.InteropServices namespace? Just wondering.
>
>
> Add
>
>    Imports System.Runtime.InteropServices
>
> at the top of the file.
>
>
> Armin
Author
24 Jan 2006 12:36 PM
Armin Zingler
"Lars Netzel" <uih***@adf.se> schrieb
> For me yes.. I don't know ANYTHING about APIs really so..

'Marshal' has nothing to do with APIs. It's a class in the framework.


Armin
Author
24 Jan 2006 5:14 PM
Dragon
Well, it's an approach too... But remember that in Windows 98/ME this
info is stored in registry, not in a file, and the retrieving using
RasGetEntryProperties is universal.
Author
24 Jan 2006 12:50 PM
Dragon
> Is there anywhere I can read about this more?

Probably, there:

http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemRuntimeInt
eropServicesMarshalClassTopic.asp
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemRuntimeInt
eropServicesMarshalAsAttributeClassTopic.asp
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemRuntimeInt
eropServicesStructLayoutAttributeClassTopic.asp

Since this three classes are in most cases essential for efficient Win32
API usage, I advice you to study them carefully.

HTH,
Roman