Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Activating Dialup connection

Posted on 2000-02-24
4
Medium Priority
?
194 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses
Course of the Month12 days, 18 hours left to enroll

971 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