Dialing a Dial-Up Networking connection from VB 
Author Message
 Dialing a Dial-Up Networking connection from VB

Hi,

How do I check using VB, if the computer that my program is running on is
connected to the Internet already?

And also, if the computer is not yet connected using a specified dial-up
connection:

How to dial, using VB, one of the dial-up networking connections in my
Dial-up networking folder, and tell it to redial a specific number of times
if the line is busy?  Does this function return any error codes?

I know this is a lot to ask, but ask I must, as I have been searching for
several hours and could not find anything.  Perhaps I am not a very good
searcher. Anyhow, I thought I would ask you good people on this news group.

Thanks heaps.

Paul Bastowski



Thu, 08 Nov 2001 03:00:00 GMT  
 Dialing a Dial-Up Networking connection from VB
Whenever Windows logs on to a dial-up connection, it changes a value in the
registry.  The following code demonstrates how to read this values to
determine whether the computer is connected or not.
NOTE: This will only work on Windows 95/98, not on Windows NT

Declarations:

'You must put the following code into the declarations section of your
project.
Public Const ERROR_SUCCESS = 0&
Public Const APINULL = 0&
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public ReturnCode As Long
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal _
hKey As Long) As Long
Declare Function RegOpenKey Lib "advapi32.dll" Alias _
"RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As _
String, phkResult As Long) As Long

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
Code
Public Function ActiveConnection() As Boolean
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
ActiveConnection = False
lpSubKey = "System\CurrentControlSet\Services\RemoteAccess"
ReturnCode = RegOpenKey(HKEY_LOCAL_MACHINE, lpSubKey, _
phkResult)

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

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

RegCloseKey (hKey)
End If

End Function

'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

To start up a dial-up networking connection, you can use this code:
Dim res
res = Shell("rundll32.exe rnaui.dll,RnaDial " & "connection_name", 1)

HTH,
Pieter Philippaerts
http://users.turboline.be/btl10148/


Quote:
> Hi,

> How do I check using VB, if the computer that my program is running on is
> connected to the Internet already?

> And also, if the computer is not yet connected using a specified dial-up
> connection:

> How to dial, using VB, one of the dial-up networking connections in my
> Dial-up networking folder, and tell it to redial a specific number of
times
> if the line is busy?  Does this function return any error codes?

> I know this is a lot to ask, but ask I must, as I have been searching for
> several hours and could not find anything.  Perhaps I am not a very good
> searcher. Anyhow, I thought I would ask you good people on this news
group.

> Thanks heaps.

> Paul Bastowski



Thu, 08 Nov 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Automatically dialing a Dial-Up Networking connection

2. looking for modem dialing (dial up networking) active-x control

3. How: Detect Dialup-Connection with Dialup-Network?

4. Starting Dial-Up network connection from VB ???

5. Ending A Dial-up Network Connection in VB

6. Calling a Dial Up Networking connection

7. Detecting dial-up networking connection status

8. disconnecting from dial up networking connection

9. dial up networking connection

10. Dial-Up Networking connection

11. Closing a Dial up Networking Connection

12. Starting dialup networking connection

 

 
Powered by phpBB® Forum Software