?
Solved

Activating Dialup connection

Posted on 2000-02-24
4
Medium Priority
?
197 Views
Last Modified: 2012-08-13
How can I activate a selected Dial up connection from a VB application (that uses FTP), and disconnect it when the VB program terminates ?
0
Comment
Question by:nimrodg080397
  • 3
4 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 2400 total points
ID: 2555043
Here you go....


'Global constant declarations
Global Const SUCCESS = 0
Global Const APINULL = 0&
Global Const MaxEntryName = 256
Global Const RAS_MaxPhoneNumber = 128
Global Const MaxCallbackNumber = RAS_MaxPhoneNumber
Global Const UNLEN = 256
Global Const PWLEN = 256
Global Const DNLEN = 18
Global Const NOT_SUPPORTED = 120&
Global Const RAS_MaxIpAddress = 15
Global Const RASP_PppIp = &H8021&

Global Const RAS_MaxDeviceType = 16 ' Self typed
Global Const RAS_MaxDeviceName = 128 ' Self typed
Global Const MAX_PATH = 260

'Declaration for lstrcpy() API
Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" _
    (lpString1 As Any, ByVal lpString2 As String) As Long

'Declaration for RasDial() API
Declare Function RasDial Lib "rasapi32" Alias "RasDialA" _
    (ByVal lpRasDialExtensions As Long, _
     ByVal lpszPhonebook As String, _
     lprasdialparams As RasDialParams, _
     ByVal dwNotifierType As Long, _
     ByVal lpvNotifier As Long, _
     lphRasConn As Long) As Long

'Declaration for RasHangUp() API
Declare Function RasHangup Lib "rasapi32" Alias "RasHangUpA" _
    (ByVal hRasConn As Long) As Long

'Type declaration for RASDIALPARAM structure
Public Type RasDialParams
    dwSize As Long
    szEntryName(MaxEntryName) As Byte
    szPhoneNumber(RAS_MaxPhoneNumber) As Byte
    szCallbackNumber(MaxCallbackNumber) As Byte
    szUserName(UNLEN) As Byte
    szPassword(PWLEN) As Byte
    szDomain(DNLEN) As Byte
End Type

'RasDial function
Function fcnRasDial(Entryname As String, _
                    PhoneNumber As String, _
                    CallbackNumber As String, _
                    Username As String, _
                    Password As String, _
                    Domain As String, _
                    hRasConn As Long) As Long
    Dim lngnRet As Long
    Dim MyRasDialParams As RasDialParams
    Dim OldMouse
         
    ' Fill in the RASDIALPARAMS structure
    MyRasDialParams.dwSize = LenB(MyRasDialParams)
    lngnRet = lstrcpy(MyRasDialParams.szEntryName(0), Entryname)
    lngnRet = lstrcpy(MyRasDialParams.szPhoneNumber(0), PhoneNumber)
    lngnRet = lstrcpy(MyRasDialParams.szCallbackNumber(0), CallbackNumber)
    lngnRet = lstrcpy(MyRasDialParams.szUserName(0), Username)
    lngnRet = lstrcpy(MyRasDialParams.szPassword(0), Password)
    lngnRet = lstrcpy(MyRasDialParams.szDomain(0), Domain)
         
    OldMouse = Screen.MousePointer
    Screen.MousePointer = vbHourglass
    ' Call RasDial
    fcnRasDial = RasDial(0, vbNullString, _
                         MyRasDialParams, 0, ByVal 0, hRasConn)
    Screen.MousePointer = OldMouse
End Function






If you wish to iterate the current ras connections, use the following:


Public Type RASCONN
    dwSize As Long
    hRasConn As Long
    szEntryName(MaxEntryName + 1) As Byte
    szDeviceType(RAS_MaxDeviceType) As Byte
    szDeviceName(RAS_MaxDeviceName) As Byte
End Type

'Declaration of RasEnumConnections () API
Public Declare Function RasEnumConnections Lib "RasApi32.DLL" Alias "RasEnumConnectionsA" _
        (lpRasconn As Any, _
         lpcb As Long, _
         lpcConnections As Long) As Long

Function EnumConns()
    Dim lRetcode As Long
    Dim lConns As Long
    Dim lSize As Long
    Dim lBuffer As Long
     
    ' Should be enough for everyone... should be improved this
    lSize = 255
     
    ReDim lpRasconn(lSize) As RASCONN
    lpRasconn(0).dwSize = LenB(lpRasconn(0))
     
    ' Calculate the buffer size
    lBuffer = lSize * 412
    ' Get the connections
    lRetcode = RasEnumConnections(lpRasconn(0), lBuffer, lConns)
    If lRetcode <> 0 Then
        ' Handle the rasHangup error
        Err.Raise vbErrorEnumConnections, "EnumConnections", fcnRasErrorString(lRetcode)
    End If
     
    Dim I As Long
    Dim mConn As CConnection
    For I = 0 To lConns - 1
        Set mConn = New CConnection
        With mConn
            .Entryname = fcnTrimNulls(StrConv(lpRasconn(I).szEntryName, vbUnicode))
            .hRasConn = lpRasconn(I).hRasConn
        End With
        mCol.Add mConn, mConn.Entryname
        Set mConn = Nothing
    Next I
End Function



Cheers!
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2555057
You can also use the "easy method" of starting dialup session by running the command "Rundll Rnaui.dll,RnaDial <Dialup name>" in a shell... for example:

id=shell("Rundll Rnaui.dll,RnaDial Erol's Internet")

Then use AppActivate and SendKeys to set focus to the "Connect To..." window and send TAB keys to get to the phone number field and ENTER key to start the connection.

Cheers!

0
 

Author Comment

by:nimrodg080397
ID: 2555106
Thanks
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2555112
You're welcome...  Thanks for the points! Glad I could help!


Cheers!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question