Solved

Create Dial-up connection programmatically

Posted on 2000-02-27
5
316 Views
Last Modified: 2010-05-18
I need to create a dial-up connection from a VB application, or create an application that will dial an ISP, logon, and open the default browser.  It seems I should be able to use the registry, but I can't seem to see how.  I can use MScomm control to open a connection, but when I call a browser, the browser doesn't recoginze that the connection is live, and calls the default dial-up connection (my client doesn't want to have the user have to create a dial-up connection).  I am open to any solution that gets me logged into an ISP and opens the default browser.  I REALLY NEED THIS IN THE NEXT 24 HOURS - OR SOONER.
Thanks
0
Comment
Question by:rebaldy
  • 3
  • 2
5 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 2562237
Hi rebaldy,

think you got it already, perhaps the users browser has the option,

"Always dial a connection"
instead of
"Dial if no connection is present"

HTH:O)Bruintje
0
 
LVL 14

Accepted Solution

by:
mcrider earned 500 total points
ID: 2562239
Here you go:

     Shell "rundll rnaui.dll,RnaDial NAME", vbNormalFocus

where: NAME is the dial-up network name... For example, If my Dialup network name is: Erols Internet

Then I would do:

     Shell "rundll rnaui.dll,RnaDial Erols Internet", vbNormalFocus



Once you do the

   Shell "rundll rnaui.dll,RnaDial NAME", vbNormalFocus

You can use the following code to set focus to the dial window and use sendkeys...


Cheers!


------------------------------------------------------------
ADD THIS TO A MODULE:
------------------------------------------------------------
Private Const GWL_ID = (-12)
Global ProgHandle As Long

Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5

Declare Function SetFocusAPI Lib "user32" Alias "SetForegroundWindow" _
    (ByVal hwnd As Long) As Long
       
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, _
    ByVal wCmd As Long) As Long
       
Private Declare Function GetWindowLW Lib "user32" Alias "GetWindowLongA" _
    (ByVal hwnd As Long, ByVal nIndex As Long) As Long
       
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long

Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" _
    (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
       
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" _
    (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Declare Function GetDesktopWindow Lib "user32" () As Long

Declare Function GetExitCodeProcess Lib "kernel32" _
    (ByVal hProcess As Long, lpExitCode As Long) As Long

Declare Function OpenProcess Lib "kernel32" _
    (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
    ByVal dwProcessId As Long) As Long

Declare Function CloseHandle Lib "kernel32" _
    (ByVal hObject As Long) As Long

Declare Function SysSetFocus Lib "user32" Alias "SetFocus" _
    (ByVal hwnd As Long) As Long

Function IsActive(hprog) As Long
    Dim hProc, RetVal As Long
    'hProc = OpenProcess(0, False, hprog)
    hProc = OpenProcess(0, hprog, False)
    If hProc <> 0 Then GetExitCodeProcess hProc, RetVal
    IsActive = (RetVal = 259)
    CloseHandle hProc
End Function

Function FindWindowLike(hWndArray() As Variant, ByVal hWndStart As Long, WindowText As String, Classname As String, ID) As Long
    Dim hwnd As Long
    Dim r As Long
    ' Hold the level of recursion:
    Static level As Long
    ' Hold the number of matching windows:
    Static iFound As Long
    Dim sWindowText As String
    Dim sClassname As String
    Dim sID
    ' Initialize if necessary:
    If level = 0 Then
        iFound = 0
        ReDim hWndArray(0 To 0)
        If hWndStart = 0 Then hWndStart = GetDesktopWindow()
    End If
    ' Increase recursion counter:
    level = level + 1
    ' Get first child window:
    hwnd = GetWindow(hWndStart, GW_CHILD)
    Do Until hwnd = 0
        DoEvents ' Not necessary
        ' Search children by recursion:
        r = FindWindowLike(hWndArray(), hwnd, WindowText, Classname, ID)
        ' Get the window text and class name:
        sWindowText = Space(255)
        r = GetWindowText(hwnd, sWindowText, 255)
        sWindowText = Left(sWindowText, r)
        sClassname = Space(255)
        r = GetClassName(hwnd, sClassname, 255)
        sClassname = Left(sClassname, r)
        ' If window is a child get the ID:
        If GetParent(hwnd) <> 0 Then
            r = GetWindowLW(hwnd, GWL_ID)
            sID = CLng("&H" & Hex(r))
        Else
            sID = Null
        End If
        ' Check that window matches the search parameters:
        If sWindowText Like WindowText And sClassname Like Classname Then
            If IsNull(ID) Then
                ' If find a match, increment counter and
                '  add handle to array:
                iFound = iFound + 1
                ReDim Preserve hWndArray(0 To iFound)
                hWndArray(iFound) = hwnd
            ElseIf Not IsNull(sID) Then
                If CLng(sID) = CLng(ID) Then
                    ' If find a match increment counter and
                    '  add handle to array:
                    iFound = iFound + 1
                    ReDim Preserve hWndArray(0 To iFound)
                    hWndArray(iFound) = hwnd
                End If
            End If
        End If
        ' Get next child window:
        hwnd = GetWindow(hwnd, GW_HWNDNEXT)
    Loop
    ' Decrement recursion counter:
    level = level - 1
    ' Return the number of windows found:
    FindWindowLike = iFound
End Function

Function LocateWindow(Source As String) As Boolean
    Static hWnds() As Variant
    Dim RetVal As Long
    Dim AppTitle As String
       
    If FindWindowLike(hWnds(), 0, Source, "*", Null) = 1 Then
        ProgHandle = hWnds(1)
        RetVal = SetFocusAPI(ProgHandle)
        DoEvents
        LocateWindow = True
    Else
        LocateWindow = False
    End If
End Function

------------------------------------------------------------

In your program, you can then do this:

do
    If LocateWindow("Connect To...") = True Then
        SendKeys "WHATEVER YOU'RE GONNA SEND", True
        Exit Do
    End If
    DoEvents
Loop
------------------------------------------------------------

When LocateWindow is called, you use whatever is in the title bar of the application you're trying to find.  It will set focus, and you just have to send the keys you want.


You can find the dialup name by going into the registry and getting the key:

HKEY_CURRENT_USER\RemoteAccess\InternetProfile

You could also look in the registry under the key:

HKEY_CURRENT_USER\Software\Microsoft\Internet Account Manager\Accounts\00000001\Connectoid

The following microsoft KB article shows you how to get information from the registry:

HOWTO: Use the Registry API to Save and Retrieve Setting
http://support.microsoft.com/support/kb/articles/q145/6/79.asp?LNG=ENG&SA=MSDN 
 


Cheers!



0
 
LVL 44

Expert Comment

by:bruintje
ID: 2562241
and if you needed more code

http://www.thescarms.com/vbasic/ShellExecute.htm

great site for other stuff too...
0
 
LVL 44

Expert Comment

by:bruintje
ID: 2562242
you where a bit faster mcrider :O)
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2562245
;-)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

820 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