[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 159
  • Last Modified:

how to dial a connection?

i know that i can make the dialind screen appear with this code
Shell "rundll rnaui.dll,RnaDial NAME", vbNormalFocus
but how do u actualyl start it dialing? it shoudln't be hard i think. thanks
0
foxhound
Asked:
foxhound
  • 2
  • 2
  • 2
  • +1
1 Solution
 
watyCommented:
Private Sub cmdConnect_Click()
   ' #VBIDEUtils#************************************************************
   ' * Programmer Name  : Waty Thierry
   ' * Web Site         : www.geocities.com/ResearchTriangle/6311/
   ' * E-Mail           : waty.thierry@usa.net
   ' * Date             : 18/10/1999
   ' * Time             : 20:31
   ' * Module Name      : frmConnectInternet
   ' * Module Filename  : Connect.frm
   ' * Procedure Name   : cmdConnect_Click
   ' * Parameters       :
   ' **********************************************************************
   ' * Comments         :
   ' *
   ' *
   ' **********************************************************************

   Dim a$
   a$ = "rundll rnaui.dll,RnaDial " & lstConnection.List(lstConnection.ListIndex)
   Shell a$, vbNormalFocus
   
End Sub
0
 
watyCommented:
To find all the available connections :

Private Const RAS_MaxDeviceType = 16
Private Const RAS95_MaxDeviceName = 128
Private Const RAS95_MaxEntryName = 256
Private Type RASCONN95
   'set dwsize to 412
   dwSize As Long
   hRasConn As Long
   szEntryName(RAS95_MaxEntryName) As Byte
   szDeviceType(RAS_MaxDeviceType) As Byte
   szDeviceName(RAS95_MaxDeviceName) As Byte
End Type
Private Type RASENTRYNAME95
   'set dwsize to 264
   dwSize As Long
   szEntryName(RAS95_MaxEntryName) 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 RasEnumEntries Lib "RasApi32.DLL" Alias "RasEnumEntriesA" (ByVal reserved As String, ByVal lpszPhonebook As String, lprasentryname As Any, lpcb As Long, lpcEntries As Long) As Long


Private Sub Form_Load()
   ' #VBIDEUtils#************************************************************
   ' * Programmer Name  : Waty Thierry
   ' * Web Site         : www.geocities.com/ResearchTriangle/6311/
   ' * E-Mail           : waty.thierry@usa.net
   ' * Date             : 18/10/1999
   ' * Time             : 20:31
   ' * Module Name      : frmConnectInternet
   ' * Module Filename  : Connect.frm
   ' * Procedure Name   : Form_Load
   ' * Parameters       :
   ' **********************************************************************
   ' * Comments         :
   ' *
   ' *
   ' **********************************************************************

   Dim s As Long, l As Long, ln As Long, a$
   ReDim r(255) As RASENTRYNAME95

   m_gradient.GradientForm Me
   
   r(0).dwSize = 264
   s = 256 * r(0).dwSize
   l = RasEnumEntries(vbNullString, vbNullString, r(0), s, ln)
   For l = 0 To ln - 1
      a$ = StrConv(r(l).szEntryName(), vbUnicode)
      lstConnection.AddItem Left$(a$, InStr(a$, Chr$(0)) - 1)
   Next
   lstConnection.ListIndex = 0
   
End Sub
0
 
foxhoundAuthor Commented:
i said the i have the code Shell "rundll rnaui.dll,RnaDial NAME", vbNormalFocus in my orginal question but that only display the 'connect' screen, doesnt' actually start dialing. i it possible? thanks
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
polaughlinCommented:
You could simply call:
SendKeys "{ENTER}"
after you call the Shell command..
That would press the enter key, causing the "Connect" button to be pressed.
0
 
foxhoundAuthor Commented:
nope, i'll tried that, the enter goes to the form rather than the 'connect' screen, even after i used vbnormalfocus
0
 
mcriderCommented:
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.


Cheers!


0
 
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now