Solved

VB Code to Dial RAS

Posted on 1998-06-10
4
441 Views
Last Modified: 2012-06-27
Please do not send me the standard rundll32 solution it is not what I am looking for.  I need some code that demonstrates the RASDIAL API.  I am writing a little app that will dial a given DUN connection, returning status messages for me to put my own verbage to for display to the user.  After it dials the first connection it needs to dial another one.  It case you have not guessed it is for implementing VPN.  I downloaded the VB32RAS.EXE File and it is a little to complicated since the RAS_AUTO.DLL has its own form which returns the status messages.  I know someone else has done this, please help.
0
Comment
Question by:sgroner
  • 2
4 Comments
 
LVL 4

Expert Comment

by:yowkee
ID: 1463037
sgroner,

  Since you have download the VB32RAS.exe, you could just get some code in the project Ras_auto.vbp to implement returning of the status message.

  What you need is the class RASError(Error.cls) and look at the code in event tmrGetConnStatus_Timer of frmAsyncDial. It use RasGetConnectStatus to get the status of existing RAS connection. If failed, use function fcnRASErrorString of class RASError to return the error. If succeed, get dwError code from type RASCONNSTATUS, then return meaningful message according to the code.

  Hope this help.

0
 
LVL 4

Expert Comment

by:yowkee
ID: 1463038
sgroner,

  Since you have download the VB32RAS.exe, you could just get some code in the project Ras_auto.vbp to implement returning of the status message.

  What you need is the class RASError(Error.cls) and look at the code in event tmrGetConnStatus_Timer of frmAsyncDial. It use RasGetConnectStatus to get the status of existing RAS connection. If failed, use function fcnRASErrorString of class RASError to return the error. If succeed, get dwError code from type RASCONNSTATUS, then return meaningful message according to the code.

  Hope this help.

0
 
LVL 5

Accepted Solution

by:
bin_huwairib earned 200 total points
ID: 1463039
sgroner,

Try the following:

1- Add form1 to project1.
2- Add command1, command2 and label1 to form1.
3- Paste this code:

Const APINULL = 0&
Const RAS_MaxDeviceType = 16
Const RAS95_MaxDeviceName = 128
Const RASBASE = 600&
Const SUCCESS = 0&
Const PENDING = (RASBASE + 0)

Const RASCS_DONE = &H2000&
Const RASCS_Connected = RASCS_DONE
Const RASCS_Disconnected = RASCS_DONE + 1&
Const RASCS_PAUSED = &H1000&
Const RASCS_OpenPort = 0&
Const RASCS_PortOpened = 1&
Const RASCS_ConnectDevice = 2&
Const RASCS_DeviceConnected = 3&
Const RASCS_AllDevicesConnected = 4&
Const RASCS_Authenticate = 5&
Const RASCS_AuthNotify = 6&
Const RASCS_AuthRetry = 7&
Const RASCS_AuthCallback = 8&
Const RASCS_AuthChangePassword = 9&
Const RASCS_AuthProject = 10&
Const RASCS_AuthLinkSpeed = 11&
Const RASCS_AuthAck = 12&
Const RASCS_ReAuthenticate = 13&
Const RASCS_Authenticated = 14&
Const RASCS_PrepareForCallback = 15&
Const RASCS_WaitForModemReset = 16&
Const RASCS_WaitForCallback = 17&
Const RASCS_Projected = 18&
Const RASCS_StartAuthentication = 19&
Const RASCS_CallbackComplete = 20&
Const RASCS_LogonNetwork = 21&
Const RASCS_Interactive = RASCS_PAUSED
Const RASCS_RetryAuthentication = RASCS_PAUSED + 1&
Const RASCS_CallbackSetByCaller = RASCS_PAUSED + 2&
Const RASCS_PasswordExpired = RASCS_PAUSED + 3&

Private Type RASDIALPARAMS95
 'set dwsize to 1052
 dwSize As Long
 szEntryName(256) As Byte
 szPhoneNumber(128) As Byte
 szCallbackNumber(128) As Byte
 szUserName(256) As Byte
 szPassword(256) As Byte
 szDomain(15) As Byte
End Type

Private Type RASCONNSTATUS95
 dwSize As Long
 rasconnstate As Long
 dwError As Long
 szDeviceType(RAS_MaxDeviceType) As Byte
 szDeviceName(RAS95_MaxDeviceName) As Byte
End Type

Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (lpString1 As Any, ByVal lpString2 As String) As Long
Private Declare Function RasDial Lib "RasApi32.DLL" Alias "RasDialA" (lpRasDialExtensions As Any, ByVal lpszPhonebook As String, lprasdialparams As Any, ByVal dwNotifierType As Long, lpvNotifier As Long, lphRasConn As Long) As Long
Private Declare Function RasHangUp Lib "RasApi32.DLL" Alias "RasHangUpA" (ByVal hRasConn As Long) As Long
Private Declare Function RasGetConnectStatus Lib "RasApi32.DLL" Alias "RasGetConnectStatusA" (ByVal hRasConn As Long, lpRASCONNSTATUS As Any) As Long

Dim hRasConn  As Long

Private Sub DialupConnection(Connection As String, UserName As String, Password As String)
 On Error GoTo Err_DialupConnection
 
 MousePointer = vbHourglass
 
 Dim lprasdialparams95 As RASDIALPARAMS95
 Dim lngRetCode As Long
 Dim lngRetlstrcpy As Long
 
 lprasdialparams95.dwSize = 1052
 lngRetlstrcpy = lstrcpy(lprasdialparams95.szEntryName(0), Connection)
 lngRetlstrcpy = lstrcpy(lprasdialparams95.szPhoneNumber(0), "")
 lngRetlstrcpy = lstrcpy(lprasdialparams95.szCallbackNumber(0), "")
 lngRetlstrcpy = lstrcpy(lprasdialparams95.szUserName(0), UserName)
 lngRetlstrcpy = lstrcpy(lprasdialparams95.szPassword(0), Password)
 lngRetlstrcpy = lstrcpy(lprasdialparams95.szDomain(0), "")
 lngRetCode = RasDial(ByVal APINULL, vbNullString, lprasdialparams95, &HFFFFFFFF, 0, hRasConn)
 
Exit_DialupConnection:
 Me.MousePointer = vbDefault
 On Error GoTo 0
 Exit Sub
 
Err_DialupConnection:
 MsgBox Err.Description, vbCritical
 Resume Exit_DialupConnection
End Sub

Private Sub Command1_Click()
 Timer1.Enabled = True
 Call DialupConnection("MyConnection1", "user1", "password")
End Sub

Private Sub Command2_Click()
 Call RasHangUp(hRasConn)
End Sub

Private Sub Form_Load()
 Timer1.Enabled = False
 Timer1.Interval = 1
 Command1.Caption = "Dial"
 Command2.Caption = "Hangup"
End Sub

Private Sub Timer1_Timer()
 Dim lpRASCONNSTATUS95 As RASCONNSTATUS95
 Dim lngRetCode  As Long
 Dim lngRASConnState As Long
 Dim lngRASError As Long
 
 lpRASCONNSTATUS95.dwSize = 160
 lngRetCode = RasGetConnectStatus(hRasConn, lpRASCONNSTATUS95)
 If lngRetCode Then
  Label1.Caption = "Failed to connect."
 
 Else  'Success
  lngRASConnState = lpRASCONNSTATUS95.rasconnstate
  lngRASError = lpRASCONNSTATUS95.dwError
  Select Case lngRASError
   Case SUCCESS, PENDING
    Select Case lngRASConnState
     Case RASCS_OpenPort
      Label1.Caption = "Attempting To Open Port..."
     Case RASCS_PortOpened
      Label1.Caption = "Port Successfully Opened"
     Case RASCS_ConnectDevice
      Label1.Caption = "Attempting to Connect Device..."
     Case RASCS_DeviceConnected
      Label1.Caption = "Device Opened"
     Case RASCS_AllDevicesConnected
      Label1.Caption = "All Devices Connected"
     Case RASCS_Authenticate
      Label1.Caption = "Authenticating..."
     Case RASCS_AuthNotify
      Label1.Caption = "Athentication Notification"
     Case RASCS_AuthRetry
      Label1.Caption = "Retrying Authentication..."
     Case RASCS_AuthCallback
      Label1.Caption = "Authentication Callback"
     Case RASCS_AuthChangePassword
      Label1.Caption = "Change Password"
     Case RASCS_AuthProject
      Label1.Caption = "Authenticating Project.."
     Case RASCS_AuthLinkSpeed
      Label1.Caption = "Authenticating Link Speed.."
     Case RASCS_AuthAck
      Label1.Caption = "Athentication Acknowlegement"
     Case RASCS_ReAuthenticate
      Label1.Caption = "ReAuthentication..."
     Case RASCS_Authenticated
      Label1.Caption = "Authenticated"
     Case RASCS_PrepareForCallback
      Label1.Caption = "Prepare For Callback"
     Case RASCS_WaitForModemReset
      Label1.Caption = "Waiting For Modem Rest..."
     Case RASCS_WaitForCallback
      Label1.Caption = "Waiting For Callback..."
     Case RASCS_Projected
      Label1.Caption = "Network Completely Configured"
     Case RASCS_StartAuthentication
      Label1.Caption = "Attempting to Open Port"
     Case RASCS_CallbackComplete
      Label1.Caption = "Callback Completed"
     Case RASCS_LogonNetwork
      Label1.Caption = "Logging On To Network"
     Case RASCS_Interactive
      Label1.Caption = "Interactive"
     Case RASCS_RetryAuthentication
      Label1.Caption = "Retry Authentication"
     Case RASCS_CallbackSetByCaller
      Label1.Caption = "CallBack Set By Caller"
     Case RASCS_PasswordExpired
      Label1.Caption = "Password Expired"
     Case RASCS_Connected
      Timer1.Enabled = False
      Label1.Caption = "Connected"
     Case RASCS_Disconnected
      Label1.Caption = "Disconnected"
     Case Else
      Label1.Caption = "Unknown State"
    End Select
   
   Case Else
    Label1.Caption = "Failed to connect."
  End Select
 End If
End Sub


Best regards
Bin Huwairib
0
 
LVL 1

Author Comment

by:sgroner
ID: 1463040
Thanks Alot the code was great.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 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…
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…

762 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

18 Experts available now in Live!

Get 1:1 Help Now