Solved

Activating Dialup connection

Posted on 2000-02-24
4
182 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 800 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now