Results 1 to 6 of 6
  1. #1
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Jeddah, Saudi Arabia
    Posts
    243
    Thanks
    0
    Thanked 1 Time in 1 Post

    Connection Manager (VB .NET 2005)

    One of my internet connections is a kind of wireless dongle attached to a USB port. The connection manager software for this loads at startup but doesn't connect automatically and there is no option to make it.

    There are 2 controls on the sofware. A drop down list to select which service to use, Postpaid or Prepaid. I use Prepaid (option 2) and a button that is captioned 'CONNECT'. This is set at the beginning and will not change.

    Unfortunately this has the habit of dropping the connection and must then be manually reconnected by clicking on the CONNECT button. This is annoying to say the least, especially when I set a download going and go to bed only to find that the damn thing disconnected 5 minutes after I left.

    What I want to do is to write a program that:

    A. Monitors the internet connection. I can do this by pinging something like www.microsoft.com or www.google.com, sites I know that are probably going to be up and active.
    B. If it finds that the connection is not active, sends a click to the CONNECT button on the connection manager screen, thus restablishing the connection.

    A I can do.

    B I have no clue.

    Any and all help will be greatly appreciated.

    Regards,
    Kevin Bell

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Connection Manager (VB .NET 2005)

    Can you switch off the connection manager software that came with the device and use Windows' built-in wireless config software?

  3. #3
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Jeddah, Saudi Arabia
    Posts
    243
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Connection Manager (VB .NET 2005)

    Unfortunately not. The WIreless dongle is a proprietary device that will only work if the driver and software are running.

    I have tried activating the software's window and sending a Control+N, the shortcut for the button, via SendKeys but this doesn't work.

    I'll keep trying and report if I have something.

    Kevin

  4. #4
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Jeddah, Saudi Arabia
    Posts
    243
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Connection Manager (VB .NET 2005)

    For anybody who is interested, a picture the main window of the Mobily application is attached. The control to focus on is the button captioned DISCONNECT. I need to click this when it is captioned CONNECT. The shortcut key is Ctrl+N but activating the window programatically and sending Ctrl+N via SendKeys doesn't work.

    Kevin
    Attached Images Attached Images

  5. #5
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Connection Manager (VB .NET 2005)

    This is VBA/VB6 - can you test it from say Excel and see if it works?
    <pre>Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    Private Declare Function GetForegroundWindow Lib "user32" () As Long
    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
    ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    Private Declare Function VkKeyScan Lib "user32" Alias "VkKeyScanA" _
    (ByVal cChar As Byte) As Integer
    Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" _
    (ByVal wCode As Long, ByVal wMapType As Long) As Long
    Private Const KEYEVENTF_KEYUP = &H2
    Private Const vbKeyShift = &H10
    Private Const vbKeyCtrl = &H11
    Private Const vbKeyAlt = &H12
    Const VK_RETURN As Integer = &HD
    Const SW_HIDE = 0

    Public Sub SendCtlN()
    Dim strCmdPath As String, OS2name
    Dim I As Long, hwnd As Long, forewin As Long
    forewin = GetForegroundWindow
    hwnd = FindWindow(vbNullString, "Mobily Connect Card")

    If hwnd = 0 Then Exit Sub
    SetForegroundWindow hwnd
    keybd_event vbKeyCtrl, 0, 0, 0
    Call Send_Keys("n", hwnd)
    keybd_event vbKeyCtrl, 0, KEYEVENTF_KEYUP, 0

    ' return focus to app
    SetForegroundWindow forewin
    End Sub
    Public Sub Send_Keys(KeysToSend As String, WindowToSendTo As Long)
    Dim ShiftDown As Boolean, AltDown As Boolean, ControlDown As Boolean
    Dim intCount As Integer
    Dim mScan As Long
    Dim a As Integer
    Dim mVK As Long

    If KeysToSend = "" Then Exit Sub
    If WindowToSendTo = 0 Then Exit Sub

    For a = 1 To Len(KeysToSend)

    mVK = VkKeyScan(Asc(Mid(KeysToSend, a, 1)))
    mScan = MapVirtualKey(mVK, 0)

    ShiftDown = (mVK And &H100)
    ControlDown = (mVK And &H200)
    AltDown = (mVK And &H400)

    mVK = mVK And &HFF
    If ShiftDown Then keybd_event &H10, 0, 0, 0
    If ControlDown And &H200 Then keybd_event &H11, 0, 0, 0
    If AltDown And &H400 Then keybd_event &H12, 0, 0, 0

    keybd_event mVK, mScan, 0, 0

    If ShiftDown Then keybd_event vbKeyShift, 0, KEYEVENTF_KEYUP, 0
    If ControlDown Then keybd_event vbKeyCtrl, 0, KEYEVENTF_KEYUP, 0
    If AltDown Then keybd_event vbKeyAlt, 0, KEYEVENTF_KEYUP, 0

    Next a

    ' SetForegroundWindow Application.hWnd

    End Sub


    Private Function FindHwnd(strCaption As String) As Long
    'Returns the handle of the specified window
    FindHwnd = FindWindow(vbNullString, strCaption)
    End Function
    </pre>

    Regards,
    Rory

    Microsoft MVP - Excel

  6. #6
    3 Star Lounger
    Join Date
    Aug 2001
    Location
    Jeddah, Saudi Arabia
    Posts
    243
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Connection Manager (VB .NET 2005)

    Rory,

    Thanks for the splendid piece of code but unfortunately it doesn't work. It sets the focus to the window alright but the Ctrl+N disappears into the ether. My guess is that somehow the button alone is set to accept the Ctrl+N. Thanks for trying anyway.

    I have solved the problem by using AutoIt. I downloaded AutoIt and created a script that does a Ping then depending on the result performs a Click event on the button. It's not pretty but it works.

    Thanks to everybody who has helped.

    Regards,

    Kevin Bell

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •