Solved

RAS Functions

Posted on 1998-11-18
1
211 Views
Last Modified: 2006-11-17
I need urgently the RAS functions in Visual Basic.
Especially RasSetEntryProperties, RasEnumDevices etc.
The more the better.
Also a sample of creating a dialup entry using these
function in VB would be great.
I'll gladly pay 200 pts for satisfactory answer.


0
Comment
Question by:adl
1 Comment
 
LVL 14

Accepted Solution

by:
waty earned 100 total points
ID: 1445502
Here are my RAS functions :

Option Explicit

' *** Used to know all active connections
Private Const ERROR_SUCCESS = 0&
Private Const APINULL = 0&
Private Const HKEY_LOCAL_MACHINE = &H80000002

Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long

' *** disconnect from the internet using VB
Private Const RAS_MAXENTRYNAME As Integer = 256
Private Const RAS_MAXDEVICETYPE As Integer = 16
Private Const RAS_MAXDEVICENAME As Integer = 128
Private Const RAS_RASCONNSIZE As Integer = 412

Private Type RasEntryName
   dwSize                          As Long
   szEntryName(RAS_MAXENTRYNAME)   As Byte
End Type

Private Type RasConn
   dwSize                          As Long
   hRasConn                        As Long
   szEntryName(RAS_MAXENTRYNAME)   As Byte
   szDeviceType(RAS_MAXDEVICETYPE) As Byte
   szDeviceName(RAS_MAXDEVICENAME) As Byte
End Type

Private Declare Function RasEnumConnections Lib "rasapi32.dll" Alias "RasEnumConnectionsA" (lpRasConn As Any, lpcb As Long, lpcConnections As Long) As Long
Private Declare Function RASHangUp Lib "rasapi32.dll" Alias "RasHangUpA" (ByVal hRasConn As Long) As Long

' *** Phone dialer
Private Declare Function tapiRequestMakeCall& Lib "TAPI32.DLL" (ByVal DestAdress$, ByVal AppName$, ByVal CalledParty$, ByVal Comment$)

Public Function ActiveConnection() As Boolean
   ' *** How can I detect if there is an active internet connection?
   ' *** For programs that rely on connecting to the internet,
   ' *** it is very useful to know whether or not the computer has an active connection.
   ' *** Whenever Windows logs on to a dial-up connection, it changes a value in the registry.

   'Here is an example of how to use the ActiveConnection function.
   '
   'If ActiveConnection = True Then
   '    Call MsgBox("You have an active connection.", vbInformation)
   'Else
   '    Call MsgBox("You have no active connections.", vbInformation)
   'End If

   Dim hKey             As Long
   Dim lpSubKey         As String
   Dim phkResult        As Long
   Dim lpValueName      As String
   Dim lpReserved       As Long
   Dim lpType           As Long
   Dim lpData           As Long
   Dim lpcbData         As Long
   Dim nRet             As Long

   ActiveConnection = False
   lpSubKey = "System\CurrentControlSet\Services\RemoteAccess"
   nRet = RegOpenKey(HKEY_LOCAL_MACHINE, lpSubKey, phkResult)

   If nRet = ERROR_SUCCESS Then
      hKey = phkResult
      lpValueName = "Remote Connection"
      lpReserved = APINULL
      lpType = APINULL
      lpData = APINULL
      lpcbData = APINULL
      nRet = RegQueryValueEx(hKey, lpValueName, lpReserved, lpType, ByVal lpData, lpcbData)
      lpcbData = Len(lpData)
      nRet = RegQueryValueEx(hKey, lpValueName, lpReserved, lpType, lpData, lpcbData)

      If nRet = ERROR_SUCCESS Then
         If lpData = 0 Then
            ActiveConnection = False
         Else
            ActiveConnection = True
         End If
      End If

      RegCloseKey (hKey)
   End If

End Function

Public Sub StartDialUp(sConnectionName As String)
   ' #VBIDEUtils#************************************************************
   ' * Programmer Name  : Waty Thierry
   ' * Web Site         : www.geocities.com/ResearchTriangle/6311/
   ' * E-Mail           : waty.thierry@usa.net
   ' * Date             : 2/10/98
   ' * Time             : 09:45
   ' * Module Name      : Internet_Module
   ' * Module Filename  : Internet.bas
   ' * Procedure Name   : StartDialUp
   ' * Parameters       :
   ' *                    sConnectionName As String
   ' **********************************************************************
   ' * Comments         : To start up a dial-up networking connection

   ' *
   ' *
   ' **********************************************************************

   Dim Res        As Variant

   Res = Shell("rundll32.exe rnaui.dll,RnaDial " & sConnectionName, 1)

End Sub

Private Function ByteToString(bytString() As Byte) As String
   Dim i As Integer

   ByteToString = ""
   i = 0
   While bytString(i) = 0&
      ByteToString = ByteToString & Chr(bytString(i))
      i = i + 1
   Wend

End Function

Public Sub HangUpConnection(sISPName As String)
   ' *** Disconnect from the internet using VB?
   ' *** If you want to terminate all connections to the internet using Visual Basic,
   ' *** you can use the Remote Access Services Hangup function.

   Dim i                As Long
   Dim lpRasConn(255)   As RasConn
   Dim lpcb             As Long
   Dim lpcConnections   As Long
   Dim hRasConn         As Long
   Dim nRet             As Long

   lpRasConn(0).dwSize = RAS_RASCONNSIZE
   lpcb = RAS_MAXENTRYNAME * lpRasConn(0).dwSize
   lpcConnections = 0
   nRet = RasEnumConnections(lpRasConn(0), lpcb, lpcConnections)

   If nRet = ERROR_SUCCESS Then
      For i = 0 To lpcConnections - 1
         If Trim(ByteToString(lpRasConn(i).szEntryName)) = Trim(sISPName) Then
            hRasConn = lpRasConn(i).hRasConn
            nRet = RASHangUp(ByVal hRasConn)
         End If
      Next
   End If

End Sub

Public Sub CreateInternetShortcutOnDesktop(sURLFile As String, sURLTarget As String)
   ' *** Creating Internet Shortcuts
   ' *** A great way of advertising your site is to offer a link from the desktop or Start Menu to your site.
   ' *** To do this, you create a URL file.
   ' *** When this file is double-clicked, it opens up the default browser with the Web Site stored
   ' *** in the file.
   ' *** The structure of the file is as follows.
   ' *** A URL file has the extension .URL, and contains the following text:

   ' *** [InternetShortcut]
   ' *** URL=http://www.geocities.com/ResearchTriangle/6311/

   ' *** EX :
   ' *** sURLFile = "C:\Windows\Desktop\PrintPreview.url"
   ' *** sURLTarget = "http://www.geocities.com/ResearchTriangle/6311/"

   ' *** Declare variables
   Dim nFileNum            As Integer

   On Error Resume Next

   ' *** Initialise Variables
   nFileNum = FreeFile

   ' *** Write the Internet Shortcut file
   Open sURLFile For Output As nFileNum
   Print #nFileNum, "[InternetShortcut]"
   Print #nFileNum, "URL=" & sURLTarget
   Close nFileNum

End Sub

Private Sub PhoneDialer(sNumber As String, sAppName As String, SName As String)
   ' *** Phone dialer
   Dim nRes       As Long
   Dim sTmp       As String

   nRes = tapiRequestMakeCall&(sNumber, sAppName, SName, "")

   If nRes <> 0 Then ' *** Error
      sTmp = "Error connecting to number: "

      Select Case nRes
         Case -2&
            sTmp = sTmp & " 'PhoneDailer not installed?"
         Case -3&
            sTmp = sTmp & "Error : " & CStr(nRes) & "."
      End Select

      MsgBox sTmp

   End If

End Sub

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

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

10 Experts available now in Live!

Get 1:1 Help Now