Jump to content

Move past a MSGBOX


Recommended Posts

Hello,

I have created an app that connects users to my VPN (it verifies Internet connectivity, establishes the connection, adds routes to other offices, and executes the logon script). Here's the part I'm stuck at:

I would like to have a MSGBOX or similar that says "Press OK to disconnect from the VPN" while at the same time in the background, continue to ping the VPN host to verify the connection hasn't terminated. The MSGBOX would stay on the user's desktop as a reminder that they are connected and also serve to disconnect when they're ready.

I'm using While and Wend but of course, the script will not go beyond the MSGBOX until the user presses the OK button, which means the ping command is not being executed.

Does anyone have any suggestions?

Thanks!!

--TB

Link to comment
Share on other sites

gui... label... button... while loop...

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

You can use this as a starting example and expand on it and change the GUI as your liking.

#include <WindowsConstants.au3>
#include <StaticConstants.au3>

Global $sHost = "localhost", $aControl[2]
Local $iTime = 4500

$hGUI = GUICreate("", @DesktopWidth, 24, 0, @DesktopHeight - 54, $WS_POPUP, $WS_EX_TOPMOST)

$iLabelWidth = 100 + (StringLen($sHost) * 10)
$aControl[0] = GUICtrlCreateLabel("", 0, 2, $iLabelWidth, 20, BitOr($SS_SUNKEN, $SS_CENTER))
$aControl[1] = GUICtrlCreateButton("Disconnect", @DesktopWidth - 100, 2, 100, 20)
_CheckConnection()

GUISetState()

AdlibRegister("_CheckConnection", $iTime) ; You can adjust the 2nd argument based on your timeout value in the Ping() command. Default timeout is 4 seconds. Add some cushion room as well.

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $aControl[1]
            AdlibUnRegister()
            If msgbox(4 + 64 + 262144, @ScriptName, "Disconnect from your VPN?") = 6 Then
                _PerformDisconnect()
                Exit
            EndIf
            AdlibRegister("_CheckConnection", $iTime)
    EndSwitch
WEnd

Func _PerformDisconnect()
    ;Do stuff here
    AdlibUnRegister()
    msgbox(0,"","Disconnected")
EndFunc

Func _CheckConnection()
    Static Local $x = 0
    If Not $x Then
        GUICtrlSetBkColor($aControl[0], 0x7CFC00)
        GUICtrlSetData($aControl[0], "Connected to: " & $sHost)
        GUICtrlSetFont($aControl[0], 10, 600)
    EndIf
        $x+=1
    If Not Ping($sHost) Then
        AdlibUnRegister()
        msgbox(16 + 262144, @ScriptName & " - ERROR!", "You were unexpectedly disconnected from your VPN." & @LF & @LF & "Application Terminating.")
        Exit
    EndIf
EndFunc
Edited by mechaflash213
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

Excellent. Thanks mechaflash. I'm not a pro in AutoIT by any means, but I follow your post pretty well. I'll give it a shot.

--TB

np. hope you get it to how you want it to work.

all of the admins/mvps would tell you I'm not a pro too ;)

if there's a function you don't know how to use, you can click on the function in the code posts, or you can type the function into SciTE and press F1, to show the help file section for that function. AutoIt has the best damn documentation I've ever seen.

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

AutoIt has the best damn documentation I've ever seen.

Not to derail but this is exactly how I feel. I'm having a hell of a time trying to learn java simply because I am so used to AutoIt's documentation and SciTE.

A true renaissance man

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...