Jump to content

Recommended Posts

Posted (edited)

I'm pretty new to writing AutoIT code, so please bare with me. I wrote a program that'll monitor the status of a VPN connection from one location to another. It'll continually ping 3 IP addresses from an INI file. The first IP is to a computer over the VPN connection. The 2nd IP is the testing computer's 1st router hop (a ISP router). The last IP address is to www.yahoo.com. This method will tell me at which point their connection is going down.

I'm having 3 problems.

1. The Minimize Button only works if all the connections are up, if any of the IPs are down the button (or red X in the upper right) won't work.

2. There appears to be some sort of refresh problem. When the program is running and is active, the 3 labels (that'll tell you if it's "connected" or "down") won't flash properly. You can see the text for a split second from the other status. Best way to explain is for you just to run the program and test it. :P

3. The "Last Internet Drop" time flashes. This I don't want. I just want it to be visible all the time like the "Last VPN Drop".

Help?

(BTW, what's the forum tag for wrapping your code in that pretty multi-colored text???) Found it! use [ autoit ] & [/ autoit ] DuH! Smacks Head. :D

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include<date.au3>
#include <INet.au3>
Global $Sec, $Min, $Hour, $Time

GUICreate("Connection Monitor", 400, 400)

;GUISetIcon("SHELL32.dll", 18)
$font = "Arial Black"
$font1 = "Arial"
$VPNDOWN = ""
$INETDOWN = ""
$VPNUP = ""
$INETUP = ""
$VPNDOWNBIT = ""
$VPNUPBIT = ""
$INETDOWNBIT = ""
$INETUPBIT = ""
$VPNSOUNDBIT = ""
$INETSOUNDBIT = ""
$1stHopDown = ""

;Import INI settings
$Location = IniRead("settings.ini", "Settings", "Location", "")
$VPNHop = IniRead("settings.ini", "Settings", "VPNHop", "")
$1stHop = IniRead("settings.ini", "Settings", "1stHop", "")
$INETHop = IniRead("settings.ini", "Settings", "INETHop", "")
$SMTPServer = IniRead("settings.ini", "Settings", "SMTPServer", "")
$Email = IniRead("settings.ini", "Settings", "Email", "")

; Show the GUI
$vpnstatus = "Testing"
$1stHopstatus = "Testing"
$inetstatus = "Testing"
GUISetFont(16, 400, 0, $font)
GUICtrlCreateLabel("VPN Status", 25, 20, 190, 60)
GUICtrlCreateLabel($vpnstatus, 240, 20, 90, 40)
GUICtrlSetBkColor(-1, 0x00FF00)
GUICtrlCreateLabel("1st Hop Status", 25, 70, 190, 60)
GUICtrlCreateLabel($1sthopstatus, 240, 70, 90, 40)
GUICtrlSetBkColor(-1, 0x00FF00)
GUICtrlCreateLabel("Internet Status", 25, 120, 190, 60)
GUICtrlCreateLabel($inetstatus, 240, 120, 90, 40)
GUICtrlSetBkColor(-1, 0x00FF00)

;Time listings
;$vpndowntime = "N/A"
;$inetdowntime = "N/A"
GUISetFont(10, 400, 0, $font1)
GUICtrlCreateLabel("Last VPN Drop", 25, 200, 190, 60)
GUICtrlCreateLabel("Last Internet Drop", 25, 220, 190, 60)
GUICtrlCreateLabel("VPN Re-established", 25, 240, 190, 60)
GUICtrlCreateLabel("Internet Re-established", 25, 260, 190, 60)


GUISetFont(9, 400, 0, $font1)
$button_min = GUICtrlCreateButton('Minimize Window', 90, 330, 180, 23)
GUISetState (@SW_HIDE)
While 1

    $msg = GUIGetMsg()

    Select
        Case $msg = $button_min
        GUISetState (@SW_HIDE)
        Case $msg = $GUI_EVENT_CLOSE
        Exit
    EndSelect

    $var = Ping($VPNHop, 250)
    
    If $var < 1  Then
    GUISetState (@SW_SHOW)
    $VPNDOWNBIT = "1"
        GUISetFont(18, 400, 0, $font)
    GUICtrlCreateLabel("", 240, 20, 210, 40)
    Sleep (250)
        GUICtrlCreateLabel("Down", 240, 20, 80, 40)
        GUICtrlSetBkColor(-1, 0xFF0000)
    Sleep (250)
    GUISetFont(10, 400, 0, $font1)
    if @hour = "12" then
        $hour = @hour
        $ampm = "PM"
    EndIf
    if @hour >= "13" then
        $hour = @hour - 12
        $ampm = "PM"
    EndIF
    if @hour < "12" then
        $hour = @hour
        $ampm = "AM"
    EndIF
    if @hour = 0 then
        $hour = 12 + @hour
        $ampm = "AM"
    EndIF
    If $VPNDOWN = "" then
        $VPNDOWN = ($hour&":"&@min&" "&$ampm)
    EndIf
    GUICtrlCreateLabel($VPNDOWN, 240, 200, 90, 40)
    If $VPNSOUNDBIT = "" then
    SoundPlay("VPNDOWN.wav",1)
    $VPNSOUNDBIT = "1"
    ENDIf
    Else
    If $VPNDOWNBIT = "1" then
        $var2 = Ping($VPNHop, 250)
        If $var2 > 1 then
            $VPNUPBIT = "1"
            if @hour = "12" then
                $hour = @hour
                $ampm = "PM"
            EndIf
            if @hour >= "13" then
                $hour = @hour - 12
                $ampm = "PM"
            EndIF
            if @hour < "12" then
                $hour = @hour
                $ampm = "AM"
            EndIF
            if @hour = 0 then
                $hour = 12 + @hour
                $ampm = "AM"
            EndIF
            If $VPNUP = "" then
                $VPNUP = ($hour&":"&@min&" "&$ampm)
            EndIf
            GUISetFont(10, 400, 0, $font1)
            GUICtrlCreateLabel($VPNUP, 240, 240, 90, 40)
            SoundPlay("VPNUP.wav",1)
            $file = FileOpen("Connection.log", 1)
            FileWriteLine($file, @MON & "/" & @MDAY & "/" & @YEAR & @CRLF)
            FileWriteLine($file, "VPN went down at: "& $VPNDOWN & @CRLF)
            FileWriteLine($file, "VPN came up at: "& $VPNUP & @CRLF)
            FileClose($file)
        EndIf
    ENDIF


        GUISetFont(18, 400, 0, $font)
    GUICtrlCreateLabel("Connected", 240, 20, 150, 40)
    GUICtrlSetBkColor(-1, 0x00FF00)
    EndIf


    $var = Ping($1stHop, 250)
    
    If $var < 1  Then
        GUISetFont(18, 400, 0, $font)
    GUICtrlCreateLabel("", 240, 70, 210, 40)
    Sleep (250)
        GUICtrlCreateLabel("Down", 240, 70, 80, 40)
        GUICtrlSetBkColor(-1, 0xFF0000)
    Sleep (250)
    $1stHopDown = "Can't connect to 1st Hop "&$1stHop
    Else
        GUISetFont(18, 400, 0, $font)
    GUICtrlCreateLabel("Connected", 240, 70, 150, 40)
    GUICtrlSetBkColor(-1, 0x00FF00)
    EndIf



    $var1 = Ping($INETHop, 250)

    If $var1 < 1 Then
    $INETDOWNBIT = "1"
        GUISetFont(18, 400, 0, $font)
    GUICtrlCreateLabel("", 240, 120, 210, 40)
    Sleep (250)
        GUICtrlCreateLabel("Down", 240, 120, 80, 40)
        GUICtrlSetBkColor(-1, 0xFF0000)
    Sleep (250)
    GUISetFont(10, 400, 0, $font1)
    if @hour = "12" then
        $hour = @hour
        $ampm = "PM"
    EndIf
    if @hour >= "13" then
        $hour = @hour - 12
        $ampm = "PM"
    EndIF
    if @hour < "12" then
        $hour = @hour
        $ampm = "AM"
    EndIF
    if @hour = 0 then
        $hour = 12 + @hour
        $ampm = "AM"
    EndIF
    If $INETDOWN = "" then
        $INETDOWN = ($hour&":"&@min&" "&$ampm)
    EndIf
    GUICtrlCreateLabel($INETDOWN, 240, 220, 90, 40)
    If $INETSOUNDBIT = "" then
    SoundPlay("INETDOWN.wav",1)
    $INETSOUNDBIT = "1"
    ENDIf
    Else
    If $INETDOWNBIT = "1" then
        $var3 = Ping($INETHop, 250)
        If $var3 > 1 then
            $INETUPBIT = "1"
            if @hour = "12" then
                $hour = @hour
                $ampm = "PM"
            EndIf
            if @hour >= "13" then
                $hour = @hour - 12
                $ampm = "PM"
            EndIF
            if @hour < "12" then
                $hour = @hour
                $ampm = "AM"
            EndIF
            if @hour = 0 then
                $hour = 12 + @hour
                $ampm = "AM"
            EndIF
            If $INETUP = "" then
                $INETUP = ($hour&":"&@min&" "&$ampm)
            EndIf
            GUISetFont(10, 400, 0, $font1)
            GUICtrlCreateLabel($INETUP, 240, 260, 90, 40)
            SoundPlay("INETUP.wav",1)
            $file = FileOpen("Connection.log", 1)
            FileWriteLine($file, "Internet went down at: "& $INETDOWN & @CRLF)
            FileWriteLine($file, "Internet came up at: "& $INETUP & @CRLF)
            FileClose($file)
        EndIf
    ENDIF




        GUISetFont(18, 400, 0, $font)
    GUICtrlCreateLabel("Connected", 240, 120, 150, 40)
    GUICtrlSetBkColor(-1, 0x00FF00)
    EndIf

    If $VPNDOWNBIT = "1" then
        IF $VPNUPBIT = "1" then
            GUISetState (@SW_SHOW)
            $s_SmtpServer = $SMTPServer
            $s_FromName = $Location
            $s_FromAddress = $Email
            $s_ToAddress = $Email
            $s_Subject = "Connection Status"
            Dim $as_Body[5]
            $as_Body[0] = "VPN went down at: "& $VPNDOWN
            $as_Body[1] = "Internet went down at: "&$INETDOWN
            $as_Body[2] = $1stHopDown
            $as_Body[3] = "VPN came back up at: "&$VPNUP
            $as_Body[4] = "Internet came back up at: "&$INETUP
            $Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
            $err = @error
                If $Response = 1 Then
                  MsgBox(0, "Success!", "Mail sent")
                Else
                    MsgBox(0, "Error!", "Mail failed with error code " & $err)
                EndIf           

            $VPNDOWN = ""
            $VPNUP = ""
            $INETDOWN = ""
            $INETUP = ""
            $VPNDOWNBIT = ""
            $VPNUPBIT = ""
            $VPNSOUNDBIT = ""
            $INETSOUNDBIT = ""
            $INETDOWNBIT = ""
        EndIF
    EndIF

WEnd
Edited by ttleser
Posted

quick question, why do you make the label over and over when u can simply just use GUICtrlSetData / GuictrlSetbkColor and stuff like that? give variables to ur GUIControls im guessing you didnt use Koda to make this?

Posted

quick question, why do you make the label over and over when u can simply just use GUICtrlSetData / GuictrlSetbkColor and stuff like that? give variables to ur GUIControls im guessing you didnt use Koda to make this?

Sorry, I looked in the help file, but since I'm a novice to programming, it's all Greek to me. Any chance you could provide my code with a small snipet of what you're talking about with GUICtrlSetData and GuictrlSetbkColor.

Also, any clue about the minimize button and X not working?

How about the 3. The "Last Internet Drop" time flashes. This I don't want. I just want it to be visible all the time like the "Last VPN Drop".

Thanks for the reply.

Posted

#include <GUIConstants.au3>

$Form1 = GUICreate("AForm1", 633, 447, 193, 115)
$Label1 = GUICtrlCreateLabel("", 88, 16, 355, 105)
GUICtrlSetFont(-1, 24, 400, 0, "MS Sans Serif")
$connect = GUICtrlCreateButton("Connect", 40, 208, 185, 81, 0)
$disconect = GUICtrlCreateButton("Disconnect", 368, 192, 193, 105, 0)
GUISetState(@SW_SHOW)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$msg = GUIGetMsg()
Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit
    Case $msg = $disconect
GUICtrlSetBkColor($Label1,0xFF2400)
GUICtrlSetData($Label1,"NOT CONNECTED")
    Case $msg = $connect
GUICtrlSetBkColor($Label1,0x4CBB17)
GUICtrlSetData($Label1,"CONNECTED")
EndSelect
WEnd

Posted

Sorry, I must be missing something here. Your example is for a simple window that when you click on a button it'll change the label from one state to another. That I can understand, but what about when you're not dealing with clicking on a button, but instead it's a loop with a bunch of IF/THEN statements?

Posted (edited)

Somehow this posted before yours even though I didn't submit it until afterwards... Oops. Reposting after your post.

Edited by ttleser
Posted (edited)

ur vars and stuff are confusin the shiz out of me but you have to learn to use variables first dude, i put an example labels in the wrongplace doin the wrong thing but its an example :P , make all your labels and then just set the data no need to create the same label over and over and over. example

Variable = Makelabel('text',paramaters)

then u can use Guictrlsetdata to change the data later

Edit: o yeah and on the issue The exit doesnt work because your in some big loop and its check if its pressed is done at the beginning so itll be stored in a buffer, and when the check comes around itll see that it was pressed but thats after the loops already gone through. So put some checks in your script with If statements.

Secondly GuiSetFont is different from GuiCtrlSetFont and i dont see why you keep setting the font its uneeded :D Guisetfont sets the GUI title font i think lol , and GUICtrlSetFont sets the font of a control like a label which is what u want to be using , but u only have to set it once so you might want to take it out of your loop

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include<date.au3>
#include <INet.au3>
Global $Sec, $Min, $Hour, $Time

GUICreate("Connection Monitor", 400, 400)

;GUISetIcon("SHELL32.dll", 18)
$font = "Arial Black"
$font1 = "Arial"
$VPNDOWN = ""
$INETDOWN = ""
$VPNUP = ""
$INETUP = ""
$VPNDOWNBIT = ""
$VPNUPBIT = ""
$INETDOWNBIT = ""
$INETUPBIT = ""
$VPNSOUNDBIT = ""
$INETSOUNDBIT = ""
$1stHopDown = ""

;Import INI settings
$Location = IniRead("settings.ini", "Settings", "Location", "")
$VPNHop = IniRead("settings.ini", "Settings", "VPNHop", "")
$1stHop = IniRead("settings.ini", "Settings", "1stHop", "")
$INETHop = IniRead("settings.ini", "Settings", "INETHop", "")
$SMTPServer = IniRead("settings.ini", "Settings", "SMTPServer", "")
$Email = IniRead("settings.ini", "Settings", "Email", "")

;Labels
$vpnstatus = GUICtrlCreateLabel("", 240, 90, 125, 32)
$1sthopstatus = GUICtrlCreateLabel("", 240, 140, 125, 32)
$inetstatus = GUICtrlCreateLabel("", 240, 190, 125, 32)


; Show the GUI
;GUISetFont(16, 400, 0, $font)
GUICtrlSetFont ($vpnstatus,16, 400, 0, $font)
GUICtrlSetFont ($1stHopstatus,16, 400, 0, $font)
GUICtrlSetFont ($inetstatus,16, 400, 0, $font)
GUISetFont(16, 400, 0, $font)
GUICtrlCreateLabel("VPN Status", 25, 90, 190, 60)
GUICtrlSetData($vpnstatus,"Connected")
GUICtrlSetBkColor($vpnstatus, 0x00FF00)
GUICtrlCreateLabel("1st Hop Status", 25, 140, 190, 60)
GUICtrlSetData($1stHopstatus,"Connected")
GUICtrlSetBkColor($1stHopstatus, 0x00FF00)
GUICtrlCreateLabel("Internet Status", 25, 190, 190, 60)
GUICtrlSetData($inetstatus,"Connected")
GUICtrlSetBkColor($inetstatus, 0x00FF00)

;Show images
;GUICtrlCreatePic("Green-Arrow.gif", 60, 20, 50, 50)


;Time listings
;$vpndowntime = "N/A"
;$inetdowntime = "N/A"
GUISetFont(10, 400, 0, $font1)
GUICtrlCreateLabel("Last VPN Drop", 25, 260, 190, 60)
GUICtrlCreateLabel("Last Internet Drop", 25, 280, 190, 60)
$internetdrop = GUICtrlCreateLabel('', 240, 320, 90, 40)

GUICtrlCreateLabel("VPN Re-established", 25, 300, 190, 60)
GUICtrlCreateLabel("Internet Re-established", 25, 320, 190, 60)
GUISetFont(9, 400, 0, $font1)
$button_min = GUICtrlCreateButton('Minimize Window', 110, 360, 180, 23)
GUISetState (@SW_HIDE)


While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then Exit

    $var = Ping($VPNHop, 250)
    If $var < 1  Then
    GUISetState (@SW_SHOW)
    $VPNDOWNBIT = "1"
    GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($vpnstatus,"")
    Sleep (250)
    GUICtrlSetData($vpnstatus,"    Down")
    GUICtrlSetBkColor($vpnstatus, 0xFF0000)
    Sleep (250)
    GUISetFont(10, 400, 0, $font1)
    if @hour = "12" then
        $hour = @hour
        $ampm = "PM"
    EndIf
    if @hour >= "13" then
        $hour = @hour - 12
        $ampm = "PM"
    EndIF
    if @hour < "12" then
        $hour = @hour
        $ampm = "AM"
    EndIF
    if @hour = 0 then
        $hour = 12 + @hour
        $ampm = "AM"
    EndIF
    If $VPNDOWN = "" then
        $VPNDOWN = ($hour&":"&@min&" "&$ampm)
    EndIf
    GUICtrlCreateLabel($VPNDOWN, 240, 260, 90, 40)
    If $VPNSOUNDBIT = "" then
    SoundPlay("VPNDOWN.wav",1)
    $VPNSOUNDBIT = "1"
    ENDIf
    Else
    If $VPNDOWNBIT = "1" then
        $var2 = Ping($VPNHop, 250)
        If $var2 > 1 then
            $VPNUPBIT = "1"
            if @hour = "12" then
                $hour = @hour
                $ampm = "PM"
            EndIf
            if @hour >= "13" then
                $hour = @hour - 12
                $ampm = "PM"
            EndIF
            if @hour < "12" then
                $hour = @hour
                $ampm = "AM"
            EndIF
            if @hour = 0 then
                $hour = 12 + @hour
                $ampm = "AM"
            EndIF
            If $VPNUP = "" then
                $VPNUP = ($hour&":"&@min&" "&$ampm)
            EndIf
            GUISetFont(10, 400, 0, $font1)
            GUICtrlCreateLabel($VPNUP, 240, 300, 90, 40)
            SoundPlay("VPNUP.wav",1)
            $file = FileOpen("Connection.log", 1)
            FileWriteLine($file, @MON & "/" & @MDAY & "/" & @YEAR & @CRLF)
            FileWriteLine($file, "VPN went down at: "& $VPNDOWN & @CRLF)
            FileWriteLine($file, "VPN came up at: "& $VPNUP & @CRLF)
            FileClose($file)
        EndIf
    ENDIF


        GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($vpnstatus,"Connected")
    GUICtrlSetBkColor($vpnstatus, 0x00FF00)
    EndIf


    $var = Ping($1stHop, 250)
   
    If $var < 1  Then
    GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($1stHopstatus,"")
    Sleep (250)
    GUICtrlSetData($1stHopstatus,"    Down")
    GUICtrlSetBkColor($1stHopstatus, 0xFF0000)
    Sleep (250)
    $1stHopDown = "Can't connect to 1st Hop "&$1stHop
    $file = FileOpen("Connection.log", 1)
    FileWriteLine($file, $1stHopDown & @CRLF)
    FileClose($file)

    Else
        GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($1stHopstatus,"Connected")
    GUICtrlSetBkColor($1stHopstatus, 0x00FF00)
    EndIf



    $var1 = Ping($INETHop, 250)

    If $var1 < 1 Then
    $INETDOWNBIT = "1"
        GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($inetstatus,"")
    Sleep (250)
    GUICtrlSetData($inetstatus,"    Down")
    GUICtrlSetBkColor($inetstatus, 0xFF0000)
    Sleep (250)
    GUISetFont(10, 400, 0, $font1)
    if @hour = "12" then
        $hour = @hour
        $ampm = "PM"
    EndIf
    if @hour >= "13" then
        $hour = @hour - 12
        $ampm = "PM"
    EndIF
    if @hour < "12" then
        $hour = @hour
        $ampm = "AM"
    EndIF
    if @hour = 0 then
        $hour = 12 + @hour
        $ampm = "AM"
    EndIF
    If $INETDOWN = "" then
        $INETDOWN = ($hour&":"&@min&" "&$ampm)
    EndIf
     GUICtrlSetData($internetdrop,$INETDOWN)
    If $INETSOUNDBIT = "" then
    SoundPlay("INETDOWN.wav",1)
    $INETSOUNDBIT = "1"
    ENDIf
    Else
    If $INETDOWNBIT = "1" then
        $var3 = Ping($INETHop, 250)
        If $var3 > 1 then
            $INETUPBIT = "1"
            if @hour = "12" then
                $hour = @hour
                $ampm = "PM"
            EndIf
            if @hour >= "13" then
                $hour = @hour - 12
                $ampm = "PM"
            EndIF
            if @hour < "12" then
                $hour = @hour
                $ampm = "AM"
            EndIF
            if @hour = 0 then
                $hour = 12 + @hour
                $ampm = "AM"
            EndIF
            If $INETUP = "" then
                $INETUP = ($hour&":"&@min&" "&$ampm)
            EndIf
            GUISetFont(10, 400, 0, $font1)
            GUICtrlSetData($internetdrop,$INETUP)
            SoundPlay("INETUP.wav",1)
            $file = FileOpen("Connection.log", 1)
            FileWriteLine($file, "Internet went down at: "& $INETDOWN & @CRLF)
            FileWriteLine($file, "Internet came up at: "& $INETUP & @CRLF)
            FileClose($file)
        EndIf
    ENDIF




        GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($inetstatus,"Connected")
    GUICtrlSetBkColor($inetstatus, 0x00FF00)
    EndIf

    If $VPNDOWNBIT = "1" then
        IF $VPNUPBIT = "1" then
            GUISetState (@SW_SHOW)
            $s_SmtpServer = $SMTPServer
            $s_FromName = $Location
            $s_FromAddress = $Email
            $s_ToAddress = $Email
            $s_Subject = "Connection Status"
            Dim $as_Body[5]
            $as_Body[0] = "VPN went down at: "& $VPNDOWN
            $as_Body[1] = "Internet went down at: "&$INETDOWN
            $as_Body[2] = $1stHopDown
            $as_Body[3] = "VPN came back up at: "&$VPNUP
            $as_Body[4] = "Internet came back up at: "&$INETUP
            $Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
            $err = @error
                If $Response = 1 Then
          MsgBox(0, "Success!", "Mail sent")
                Else
                    MsgBox(0, "Error!", "Mail failed with error code " & $err)
                EndIf         

            $VPNDOWN = ""
            $VPNUP = ""
            $INETDOWN = ""
            $INETUP = ""
            $VPNDOWNBIT = ""
            $VPNUPBIT = ""
            $VPNSOUNDBIT = ""
            $INETSOUNDBIT = ""
            $INETDOWNBIT = ""
        EndIF
    EndIF

WEnd
Edited by Thatsgreat2345
Posted

Thatsgreat2345

Ok, after playing with the code a bit more and reading, re-reading the help file as well as seeing some examples I got it working. Very nice, it's flashing better without the other color glitch. It also made me changing some settings a little easier. I corrected the Variable problem as well as the font problem, at least hopefully I corrected it. Thanks for the suggestions.. :P

Edit: o yeah and on the issue The exit doesnt work because your in some big loop and its check if its pressed is done at the beginning so itll be stored in a buffer, and when the check comes around itll see that it was pressed but thats after the loops already gone through. So put some checks in your script with If statements.

Any suggestions on how I'd start on that?

Here's the revised code:

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include<date.au3>
#include <INet.au3>
Global $Sec, $Min, $Hour, $Time

GUICreate("Connection Monitor", 400, 400)

;GUISetIcon("SHELL32.dll", 18)
$font = "Arial Black"
$font1 = "Arial"
$VPNDOWN = ""
$INETDOWN = ""
$VPNUP = ""
$INETUP = ""
$VPNDOWNBIT = ""
$VPNUPBIT = ""
$INETDOWNBIT = ""
$INETUPBIT = ""
$VPNSOUNDBIT = ""
$INETSOUNDBIT = ""
$1stHopDown = ""

;Import INI settings
$Location = IniRead("settings.ini", "Settings", "Location", "")
$VPNHop = IniRead("settings.ini", "Settings", "VPNHop", "")
$1stHop = IniRead("settings.ini", "Settings", "1stHop", "")
$INETHop = IniRead("settings.ini", "Settings", "INETHop", "")
$SMTPServer = IniRead("settings.ini", "Settings", "SMTPServer", "")
$Email = IniRead("settings.ini", "Settings", "Email", "")

;Labels
$vpnstatus    = GUICtrlCreateLabel("", 240, 90, 125, 32)
$1sthopstatus = GUICtrlCreateLabel("", 240, 140, 125, 32)
$inetstatus   = GUICtrlCreateLabel("", 240, 190, 125, 32)
$VPNDOWNTIME  = GUICtrlCreateLabel("", 280, 260, 90, 40)
$INETDOWNTIME = GUICtrlCreateLabel("", 280, 280, 90, 40)
$VPNUPTIME    = GUICtrlCreateLabel("", 280, 300, 90, 40)
$INETUPTIME   = GUICtrlCreateLabel("", 280, 320, 90, 40)


; Show the GUI
;GUISetFont(16, 400, 0, $font)
GUICtrlSetFont ($vpnstatus,16, 400, 0, $font)
GUICtrlSetFont ($1stHopstatus,16, 400, 0, $font)
GUICtrlSetFont ($inetstatus,16, 400, 0, $font)
GUICtrlSetFont ($VPNDOWNTIME,10, 400, 0, $font1)
GUICtrlSetFont ($VPNUPTIME,10, 400, 0, $font1)
GUICtrlSetFont ($INETDOWNTIME,10, 400, 0, $font1)
GUICtrlSetFont ($INETUPTIME,10, 400, 0, $font1)
GUICtrlSetFont ($VPNDOWN,10, 400, 0, $font1)
GUICtrlSetFont ($VPNUP,10, 400, 0, $font1)
GUICtrlSetFont ($INETDOWN,10, 400, 0, $font1)
GUICtrlSetFont ($INETUP,10, 400, 0, $font1)

GUISetFont(16, 400, 0, $font)
GUICtrlCreateLabel("VPN Status", 25, 90, 190, 60)
GUICtrlSetData($vpnstatus,"Connected")
GUICtrlSetBkColor($vpnstatus, 0x00FF00)
GUICtrlCreateLabel("1st Hop Status", 25, 140, 190, 60)
GUICtrlSetData($1stHopstatus,"Connected")
GUICtrlSetBkColor($1stHopstatus, 0x00FF00)
GUICtrlCreateLabel("Internet Status", 25, 190, 190, 60)
GUICtrlSetData($inetstatus,"Connected")
GUICtrlSetBkColor($inetstatus, 0x00FF00)

;Show images
;GUICtrlCreatePic("Green-Arrow.gif", 60, 20, 50, 50)


;Time listings
;$vpndowntime = "N/A"
;$inetdowntime = "N/A"
GUISetFont(10, 400, 0, $font1)
GUICtrlCreateLabel("Last VPN Drop", 60, 260, 190, 60)
GUICtrlCreateLabel("Last Internet Drop", 60, 280, 190, 60)
GUICtrlCreateLabel("VPN Re-established", 60, 300, 190, 60)
GUICtrlCreateLabel("Internet Re-established", 60, 320, 190, 60)
GUISetFont(9, 400, 0, $font1)
$button_min = GUICtrlCreateButton('Minimize Window', 110, 360, 180, 23)
GUISetState (@SW_HIDE)



While 1

    $msg = GUIGetMsg()

    Select
        Case $msg = $button_min
        GUISetState (@SW_HIDE)
        Case $msg = $GUI_EVENT_CLOSE
        Exit
    EndSelect

    $var = Ping($VPNHop, 250)
    
    If $var < 1  Then
    GUISetState (@SW_SHOW)
    $VPNDOWNBIT = "1"
        GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($vpnstatus,"")
    Sleep (250)
    GUICtrlSetData($vpnstatus,"    Down")
        GUICtrlSetBkColor($vpnstatus, 0xFF0000)
    Sleep (250)
    GUISetFont(10, 400, 0, $font1)
    if @hour = "12" then
        $hour = @hour
        $ampm = "PM"
    EndIf
    if @hour >= "13" then
        $hour = @hour - 12
        $ampm = "PM"
    EndIF
    if @hour < "12" then
        $hour = @hour
        $ampm = "AM"
    EndIF
    if @hour = 0 then
        $hour = 12 + @hour
        $ampm = "AM"
    EndIF
    If $VPNDOWN = "" then
        $VPNDOWN = ($hour&":"&@min&" "&$ampm)
    EndIf
    GUICtrlSetData($VPNDOWNTIME,$VPNDOWN)
    If $VPNSOUNDBIT = "" then
    SoundPlay("VPNDOWN.wav",1)
    $VPNSOUNDBIT = "1"
    ENDIf
    Else
    If $VPNDOWNBIT = "1" then
        $var2 = Ping($VPNHop, 250)
        If $var2 > 1 then
            $VPNUPBIT = "1"
            if @hour = "12" then
                $hour = @hour
                $ampm = "PM"
            EndIf
            if @hour >= "13" then
                $hour = @hour - 12
                $ampm = "PM"
            EndIF
            if @hour < "12" then
                $hour = @hour
                $ampm = "AM"
            EndIF
            if @hour = 0 then
                $hour = 12 + @hour
                $ampm = "AM"
            EndIF
            If $VPNUP = "" then
                $VPNUP = ($hour&":"&@min&" "&$ampm)
            EndIf

            GUICtrlSetData($VPNUPTIME,$VPNUP)

            SoundPlay("VPNUP.wav",1)
            $file = FileOpen("Connection.log", 1)
            FileWriteLine($file, @MON & "/" & @MDAY & "/" & @YEAR & @CRLF)
            FileWriteLine($file, "VPN went down at: "& $VPNDOWN & @CRLF)
            FileWriteLine($file, "VPN came up at: "& $VPNUP & @CRLF)
            FileClose($file)
        EndIf
    ENDIF


        GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($vpnstatus,"Connected")
    GUICtrlSetBkColor($vpnstatus, 0x00FF00)
    EndIf


    $var = Ping($1stHop, 250)
    
    If $var < 1  Then
        GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($1stHopstatus,"")
    Sleep (250)
    GUICtrlSetData($1stHopstatus,"    Down")
        GUICtrlSetBkColor($1stHopstatus, 0xFF0000)
    Sleep (250)
    $1stHopDown = "Can't connect to 1st Hop "&$1stHop
    $file = FileOpen("Connection.log", 1)
    FileWriteLine($file, $1stHopDown & @CRLF)
    FileClose($file)

    Else
        GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($1stHopstatus,"Connected")
    GUICtrlSetBkColor($1stHopstatus, 0x00FF00)
    EndIf



    $var1 = Ping($INETHop, 250)

    If $var1 < 1 Then
    $INETDOWNBIT = "1"
        GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($inetstatus,"")
    Sleep (250)
    GUICtrlSetData($inetstatus,"    Down")
        GUICtrlSetBkColor($inetstatus, 0xFF0000)
    Sleep (250)
    GUISetFont(10, 400, 0, $font1)
    if @hour = "12" then
        $hour = @hour
        $ampm = "PM"
    EndIf
    if @hour >= "13" then
        $hour = @hour - 12
        $ampm = "PM"
    EndIF
    if @hour < "12" then
        $hour = @hour
        $ampm = "AM"
    EndIF
    if @hour = 0 then
        $hour = 12 + @hour
        $ampm = "AM"
    EndIF
    If $INETDOWN = "" then
        $INETDOWN = ($hour&":"&@min&" "&$ampm)
    EndIf
    GUICtrlSetData($INETDOWNTIME,$INETDOWN)
    If $INETSOUNDBIT = "" then
    SoundPlay("INETDOWN.wav",1)
    $INETSOUNDBIT = "1"
    ENDIf
    Else
    If $INETDOWNBIT = "1" then
        $var3 = Ping($INETHop, 250)
        If $var3 > 1 then
            $INETUPBIT = "1"
            if @hour = "12" then
                $hour = @hour
                $ampm = "PM"
            EndIf
            if @hour >= "13" then
                $hour = @hour - 12
                $ampm = "PM"
            EndIF
            if @hour < "12" then
                $hour = @hour
                $ampm = "AM"
            EndIF
            if @hour = 0 then
                $hour = 12 + @hour
                $ampm = "AM"
            EndIF
            If $INETUP = "" then
                $INETUP = ($hour&":"&@min&" "&$ampm)
            EndIf
            GUICtrlSetData($INETUPTIME,$INETUP)
            SoundPlay("INETUP.wav",1)
            $file = FileOpen("Connection.log", 1)
            FileWriteLine($file, "Internet went down at: "& $INETDOWN & @CRLF)
            FileWriteLine($file, "Internet came up at: "& $INETUP & @CRLF)
            FileClose($file)
        EndIf
    ENDIF




        GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($inetstatus,"Connected")
    GUICtrlSetBkColor($inetstatus, 0x00FF00)
    EndIf

    If $VPNDOWNBIT = "1" then
        IF $VPNUPBIT = "1" then
            GUISetState (@SW_SHOW)
            $s_SmtpServer = $SMTPServer
            $s_FromName = $Location
            $s_FromAddress = $Email
            $s_ToAddress = $Email
            $s_Subject = "Connection Status"
            Dim $as_Body[5]
            $as_Body[0] = "VPN went down at: "& $VPNDOWN
            $as_Body[1] = "Internet went down at: "&$INETDOWN
            $as_Body[2] = $1stHopDown
            $as_Body[3] = "VPN came back up at: "&$VPNUP
            $as_Body[4] = "Internet came back up at: "&$INETUP
            $Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
            $err = @error
                If $Response = 1 Then
                MsgBox(0, "Email Sent", "                    Connections have been reestablished."& @CRLF&"An Email has been sent to Terry letting him know what happened.")
                Else
                    MsgBox(0, "Error!", "Mail failed with error code " & $err)
                EndIf           

            $VPNDOWN = ""
            $VPNUP = ""
            $INETDOWN = ""
            $INETUP = ""
            $VPNDOWNBIT = ""
            $VPNUPBIT = ""
            $VPNSOUNDBIT = ""
            $INETSOUNDBIT = ""
            $INETDOWNBIT = ""
        EndIF
    EndIF

WEnd
Posted

Would you suggest something like this several times throughout the code?

If $msg = $button_min

GUISetState (@SW_HIDE)

EndIF

If $msg = $GUI_EVENT_CLOSE

Exit

EndIf

Posted

Ok

1. Minimize works no matter what Lines(90 & 91)

2.Why Hide then show the GUI? Lines(81,99)

3. Why set the data to blank and then set it to Down?Lines(101,102)

4.Guisetfont again Line(106)

5. All your if statements , can be changed to elseifs. Lines (107 - 122)

6. If there is just one line of code after an IF you don't need endif just put it after the then, and u dont need (). Line(125)

7. If no soundbit play sound? Lines(128-131)

8. Else then and If statement, easily cured with elseif. Line(133)

9. Elseif. Lines(135,154)

10. 1 line if , then put after if Line(155)

11. FileOpen is not really needed since your not doing an error check if it was succesfully opened or not Line(160)

12. Guisetfont again Line(169)

13. Guisetfont again Line(177)

14. Why set blank Line(178,179)

15.No need for FileOpen , its already declared anyways Line(184)

16.Guisetfont agian Line(189)

much more to lazy to continue cause they are all the same unneededness

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include<date.au3>
#include <INet.au3>
Global $Sec, $Min, $Hour, $Time

GUICreate("Connection Monitor", 400, 400)

;GUISetIcon("SHELL32.dll", 18)
$font = "Arial Black"
$font1 = "Arial"
$VPNDOWN = ""
$INETDOWN = ""
$VPNUP = ""
$INETUP = ""
$VPNDOWNBIT = ""
$VPNUPBIT = ""
$INETDOWNBIT = ""
$INETUPBIT = ""
$VPNSOUNDBIT = ""
$INETSOUNDBIT = ""
$1stHopDown = ""
$file = "Connection.log"
;Import INI settings
$Location = IniRead("settings.ini", "Settings", "Location", "")
$VPNHop = IniRead("settings.ini", "Settings", "VPNHop", "")
$1stHop = IniRead("settings.ini", "Settings", "1stHop", "")
$INETHop = IniRead("settings.ini", "Settings", "INETHop", "")
$SMTPServer = IniRead("settings.ini", "Settings", "SMTPServer", "")
$Email = IniRead("settings.ini", "Settings", "Email", "")

;Labels
$vpnstatus    = GUICtrlCreateLabel("", 240, 90, 125, 32)
$1sthopstatus = GUICtrlCreateLabel("", 240, 140, 125, 32)
$inetstatus   = GUICtrlCreateLabel("", 240, 190, 125, 32)
$VPNDOWNTIME  = GUICtrlCreateLabel("", 280, 260, 90, 40)
$INETDOWNTIME = GUICtrlCreateLabel("", 280, 280, 90, 40)
$VPNUPTIME    = GUICtrlCreateLabel("", 280, 300, 90, 40)
$INETUPTIME   = GUICtrlCreateLabel("", 280, 320, 90, 40)


; Show the GUI
;GUISetFont(16, 400, 0, $font)
GUICtrlSetFont ($vpnstatus,16, 400, 0, $font)
GUICtrlSetFont ($1stHopstatus,16, 400, 0, $font)
GUICtrlSetFont ($inetstatus,16, 400, 0, $font)
GUICtrlSetFont ($VPNDOWNTIME,10, 400, 0, $font1)
GUICtrlSetFont ($VPNUPTIME,10, 400, 0, $font1)
GUICtrlSetFont ($INETDOWNTIME,10, 400, 0, $font1)
GUICtrlSetFont ($INETUPTIME,10, 400, 0, $font1)
GUICtrlSetFont ($VPNDOWN,10, 400, 0, $font1)
GUICtrlSetFont ($VPNUP,10, 400, 0, $font1)
GUICtrlSetFont ($INETDOWN,10, 400, 0, $font1)
GUICtrlSetFont ($INETUP,10, 400, 0, $font1)

GUISetFont(16, 400, 0, $font)
GUICtrlCreateLabel("VPN Status", 25, 90, 190, 60)
GUICtrlSetData($vpnstatus,"Connected")
GUICtrlSetBkColor($vpnstatus, 0x00FF00)
GUICtrlCreateLabel("1st Hop Status", 25, 140, 190, 60)
GUICtrlSetData($1stHopstatus,"Connected")
GUICtrlSetBkColor($1stHopstatus, 0x00FF00)
GUICtrlCreateLabel("Internet Status", 25, 190, 190, 60)
GUICtrlSetData($inetstatus,"Connected")
GUICtrlSetBkColor($inetstatus, 0x00FF00)

;Show images
;GUICtrlCreatePic("Green-Arrow.gif", 60, 20, 50, 50)


;Time listings
;$vpndowntime = "N/A"
;$inetdowntime = "N/A"
GUISetFont(10, 400, 0, $font1)
GUICtrlCreateLabel("Last VPN Drop", 60, 260, 190, 60)
GUICtrlCreateLabel("Last Internet Drop", 60, 280, 190, 60)
GUICtrlCreateLabel("VPN Re-established", 60, 300, 190, 60)
GUICtrlCreateLabel("Internet Re-established", 60, 320, 190, 60)
GUISetFont(9, 400, 0, $font1)
$button_min = GUICtrlCreateButton('Minimize Window', 110, 360, 180, 23)
;GUISetState (@SW_HIDE)
GUISetState (@SW_SHOW)


While 1

    $msg = GUIGetMsg()

    Select
        ;Case $msg = $button_min
       ; GUISetState (@SW_HIDE)
        Case $msg = $GUI_EVENT_CLOSE
        Exit
    EndSelect

    $var = Ping($VPNHop, 250)
   
    If $var < 1  Then
    ;GUISetState (@SW_SHOW)
    $VPNDOWNBIT = "1"
    ;GUICtrlSetData($vpnstatus,"")
    ;Sleep (250)
    GUICtrlSetData($vpnstatus,"    Down")
    GUICtrlSetBkColor($vpnstatus, 0xFF0000)
    ;Sleep (250)
    ;GUISetFont(10, 400, 0, $font1)
    If @hour = "12" Then
        $hour = @hour
        $ampm = "PM"
    ;EndIf
    ElseIf @hour >= "13" Then
        $hour = @hour - 12
        $ampm = "PM"
    ;EndIF
    ElseIf @hour < "12" Then
        $hour = @hour
        $ampm = "AM"
    ;EndIF
    ElseIf @hour = 0 Then
        $hour = 12 + @hour
        $ampm = "AM"
    EndIF
    
    
    If $VPNDOWN = "" Then $VPNDOWN = $hour&":"&@min&" "&$ampm 
   ; EndIf
    GUICtrlSetData($VPNDOWNTIME,$VPNDOWN)
    If $VPNSOUNDBIT = "" then
    SoundPlay("VPNDOWN.wav",1)
    $VPNSOUNDBIT = "1"
    EndIf

    ElseIf $VPNDOWNBIT = "1" then
        
        $var2 = Ping($VPNHop, 250)
        
        If $var2 > 1 Then 
            $VPNUPBIT = "1"
            If @hour = "12" Then
                $hour = @hour
                $ampm = "PM"
           ;EndIf
            ElseIf @hour >= "13" Then
                $hour = @hour - 12
                $ampm = "PM"
           ; EndIF
            ElseIf @hour < "12" Then
                $hour = @hour
                $ampm = "AM"
            ;EndIF
            ElseIf @hour = 0 Then
                $hour = 12 + @hour
                $ampm = "AM"
            EndIF
            If $VPNUP = "" then $VPNUP = $hour&":"&@min&" "&$ampm
            ;EndIf
            GUICtrlSetData($VPNUPTIME,$VPNUP)
            SoundPlay("VPNUP.wav",1)
            
           ; $file = FileOpen("Connection.log", 1)
            
            FileWriteLine($file, @MON & "/" & @MDAY & "/" & @YEAR & @CRLF)
            FileWriteLine($file, "VPN went down at: "& $VPNDOWN & @CRLF)
            FileWriteLine($file, "VPN came up at: "& $VPNUP & @CRLF)
            ;FileClose($file)
        EndIf
    EndIf

    ;GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($vpnstatus,"Connected")
    GUICtrlSetBkColor($vpnstatus, 0x00FF00)


    $var = Ping($1stHop, 250)
   
    If $var < 1  Then
    ;GUISetFont(18, 400, 0, $font)
    ;GUICtrlSetData($1stHopstatus,"")
    ;Sleep (250)
    GUICtrlSetData($1stHopstatus,"    Down")
    GUICtrlSetBkColor($1stHopstatus, 0xFF0000)
    ;Sleep (250)
    $1stHopDown = "Can't connect to 1st Hop "& $1stHop
    ;$file = FileOpen("Connection.log", 1)
    FileWriteLine($file, $1stHopDown & @CRLF)
    ;FileClose($file)

    Else
    ;GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($1stHopstatus,"Connected")
    GUICtrlSetBkColor($1stHopstatus, 0x00FF00)
    EndIf



    $var1 = Ping($INETHop, 250)

    If $var1 < 1 Then
    $INETDOWNBIT = "1"
    ;GUISetFont(18, 400, 0, $font)
    ;GUICtrlSetData($inetstatus,"")
    ;Sleep (250)
    GUICtrlSetData($inetstatus,"    Down")
    GUICtrlSetBkColor($inetstatus, 0xFF0000)
   ; Sleep (250)
   ; GUISetFont(10, 400, 0, $font1)
    if @hour = "12" then
        $hour = @hour
        $ampm = "PM"
    EndIf
    if @hour >= "13" then
        $hour = @hour - 12
        $ampm = "PM"
    EndIF
    if @hour < "12" then
        $hour = @hour
        $ampm = "AM"
    EndIF
    if @hour = 0 then
        $hour = 12 + @hour
        $ampm = "AM"
    EndIF
    If $INETDOWN = "" then
        $INETDOWN = ($hour&":"&@min&" "&$ampm)
    EndIf
    GUICtrlSetData($INETDOWNTIME,$INETDOWN)
    If $INETSOUNDBIT = "" then
    SoundPlay("INETDOWN.wav",1)
    $INETSOUNDBIT = "1"
    ENDIf
    Else
    If $INETDOWNBIT = "1" then
        $var3 = Ping($INETHop, 250)
        If $var3 > 1 then
            $INETUPBIT = "1"
            if @hour = "12" then
                $hour = @hour
                $ampm = "PM"
            EndIf
            if @hour >= "13" then
                $hour = @hour - 12
                $ampm = "PM"
            EndIF
            if @hour < "12" then
                $hour = @hour
                $ampm = "AM"
            EndIF
            if @hour = 0 then
                $hour = 12 + @hour
                $ampm = "AM"
            EndIF
            If $INETUP = "" then
                $INETUP = ($hour&":"&@min&" "&$ampm)
            EndIf
            GUICtrlSetData($INETUPTIME,$INETUP)
            SoundPlay("INETUP.wav",1)
            ;$file = FileOpen("Connection.log", 1)
            FileWriteLine($file, "Internet went down at: "& $INETDOWN & @CRLF)
            FileWriteLine($file, "Internet came up at: "& $INETUP & @CRLF)
            ;FileClose($file)
        EndIf
    ENDIF




    ;GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($inetstatus,"Connected")
    GUICtrlSetBkColor($inetstatus, 0x00FF00)
    EndIf

    If $VPNDOWNBIT = "1" then
        IF $VPNUPBIT = "1" then
           ; GUISetState (@SW_SHOW)
            $s_SmtpServer = $SMTPServer
            $s_FromName = $Location
            $s_FromAddress = $Email
            $s_ToAddress = $Email
            $s_Subject = "Connection Status"
            Dim $as_Body[5]
            $as_Body[0] = "VPN went down at: "& $VPNDOWN
            $as_Body[1] = "Internet went down at: "&$INETDOWN
            $as_Body[2] = $1stHopDown
            $as_Body[3] = "VPN came back up at: "&$VPNUP
            $as_Body[4] = "Internet came back up at: "&$INETUP
            $Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
            $err = @error
                If $Response = 1 Then
          MsgBox(0, "Email Sent", "                    Connections have been reestablished."& @CRLF&"An Email has been sent to Terry letting him know what happened.")
                Else
                    MsgBox(0, "Error!", "Mail failed with error code " & $err)
                EndIf         

            $VPNDOWN = ""
            $VPNUP = ""
            $INETDOWN = ""
            $INETUP = ""
            $VPNDOWNBIT = ""
            $VPNUPBIT = ""
            $VPNSOUNDBIT = ""
            $INETSOUNDBIT = ""
            $INETDOWNBIT = ""
        EndIF
    EndIF

WEnd
Posted

Thanks for the reply and work over on the code. I do appreciate the workover. I need to head home and look all this over. I'll reply to your listing tomorrow as there are reasons to what I need. :P

Posted

Thatsgreat2345, to answer your questions.

1. Minimize works no matter what Lines(90 & 91): Actually, the MINIMIZE WINDOW button at the bottom of the screen doesn't work, actually it's really hard to press. Can you tell me what I'm doing wrong?

2.Why Hide then show the GUI? Lines(81,99):Because I only want the program visible when any connection is down, otherwise I want it hidden.

3. Why set the data to blank and then set it to Down?Lines(101,102):Because I want the text to flash, making it get the user's attention better.

7. If no soundbit play sound? Lines(128-131):Basically I used it as a way to make sure the sound is played only once during the loop for checking the connection.

14. Why set blank Line(178,179):Same answer as #3

I appreciate the comments and corrections to poorly written code. It's still probably very poorly written, but with your help I'm learning and correcting previous problems. Below is the corrected code. I added some Functions to it to help correct issues with the _ (minimize) and X (close) window buttons working, which it DID!!!! Now they react immediately instead of delayed. Unfortunately my "Minimize Window" button I added to the GUI isn't working, heck you can't really click on it most of the time. I found that if you move your cursor to the right of it, most of the time you can click on it, but it still doesn't "hide" the GUI.

Any thoughts?

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include<date.au3>
#include <INet.au3>
Global $Sec, $Min, $Hour, $Time

GUICreate("Connection Monitor", 400, 400)
Opt("GUIOnEventMode", 1)

$font = "Arial Black"
$font1 = "Arial"
GUISetIcon("SHELL32.dll", 18)
GUISetFont(10, 400, 0, $font1)
$VPNDOWN = ""
$INETDOWN = ""
$VPNUP = ""
$INETUP = ""
$VPNDOWNBIT = ""
$VPNUPBIT = ""
$INETDOWNBIT = ""
$INETUPBIT = ""
$VPNSOUNDBIT = ""
$INETSOUNDBIT = ""
$1stHopDown = ""
;Import INI settings
$file = IniRead("settings.ini", "Settings", "logfile", "")
$Location = IniRead("settings.ini", "Settings", "Location", "")
$VPNHop = IniRead("settings.ini", "Settings", "VPNHop", "")
$1stHop = IniRead("settings.ini", "Settings", "1stHop", "")
$INETHop = IniRead("settings.ini", "Settings", "INETHop", "")
$SMTPServer = IniRead("settings.ini", "Settings", "SMTPServer", "")
$Email = IniRead("settings.ini", "Settings", "Email", "")
;Labels
$vpnstatus    = GUICtrlCreateLabel("", 240, 90, 125, 32)
$1sthopstatus = GUICtrlCreateLabel("", 240, 140, 125, 32)
$inetstatus   = GUICtrlCreateLabel("", 240, 190, 125, 32)
$VPNDOWNTIME  = GUICtrlCreateLabel("", 280, 260, 90, 40)
$INETDOWNTIME = GUICtrlCreateLabel("", 280, 280, 90, 40)
$VPNUPTIME    = GUICtrlCreateLabel("", 280, 300, 90, 40)
$INETUPTIME   = GUICtrlCreateLabel("", 280, 320, 90, 40)
; Show the GUI
GUICtrlSetFont ($vpnstatus,16, 400, 0, $font)
GUICtrlSetFont ($1stHopstatus,16, 400, 0, $font)
GUICtrlSetFont ($inetstatus,16, 400, 0, $font)
GUICtrlSetFont ($VPNDOWNTIME,10, 400, 0, $font1)
GUICtrlSetFont ($VPNUPTIME,10, 400, 0, $font1)
GUICtrlSetFont ($INETDOWNTIME,10, 400, 0, $font1)
GUICtrlSetFont ($INETUPTIME,10, 400, 0, $font1)
GUICtrlSetFont ($VPNDOWN,10, 400, 0, $font1)
GUICtrlSetFont ($VPNUP,10, 400, 0, $font1)
GUICtrlSetFont ($INETDOWN,10, 400, 0, $font1)
GUICtrlSetFont ($INETUP,10, 400, 0, $font1)
GUICtrlCreateLabel("VPN Status", 25, 90, 190, 60)
GUICtrlSetData($vpnstatus,"Connected")
GUICtrlSetBkColor($vpnstatus, 0x00FF00)
GUICtrlCreateLabel("1st Hop Status", 25, 140, 190, 60)
GUICtrlSetData($1stHopstatus,"Connected")
GUICtrlSetBkColor($1stHopstatus, 0x00FF00)
GUICtrlCreateLabel("Internet Status", 25, 190, 190, 60)
GUICtrlSetData($inetstatus,"Connected")
GUICtrlSetBkColor($inetstatus, 0x00FF00)


;Show images
;GUICtrlCreatePic("Green-Arrow.gif", 60, 20, 50, 50)


;Time listings
GUICtrlCreateLabel("Last VPN Drop", 60, 260, 190, 60)
GUICtrlCreateLabel("Last Internet Drop", 60, 280, 190, 60)
GUICtrlCreateLabel("VPN Re-established", 60, 300, 190, 60)
GUICtrlCreateLabel("Internet Re-established", 60, 320, 190, 60)
$button_min = GUICtrlCreateButton('Minimize Window', 110, 360, 180, 23)
GUISetState (@SW_HIDE)

;System Tray
;Opt("TrayMenuMode",1)
TraySetIcon("Shell32.dll", 18)
;$restoreitem  = TrayCreateItem("Restore")
;TrayCreateItem("")
;$exititem   = TrayCreateItem("Exit")
;TraySetState()

;Call Functions
GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")
GUISetOnEvent($button_min, "Minimized_button_pressed")

While 1
;    $msg = GUIGetMsg()

$var = Ping($VPNHop, 250)
    
    If $var < 1  Then
    GUISetState (@SW_SHOW)
    $VPNDOWNBIT = "1"
    GUICtrlSetData($vpnstatus,"")
    Sleep (200)
    GUICtrlSetData($vpnstatus,"    Down")
    GUICtrlSetBkColor($vpnstatus, 0xFF0000)
    Sleep (200)
    If @hour = "12" then
        $hour = @hour
        $ampm = "PM"
    ElseIf @hour >= "13" then
        $hour = @hour - 12
        $ampm = "PM"
    ElseIf @hour < "12" then
        $hour = @hour
        $ampm = "AM"
    ElseIf @hour = 0 then
        $hour = 12 + @hour
        $ampm = "AM"
    EndIf
    
    If $VPNDOWN = "" then $VPNDOWN = ($hour&":"&@min&" "&$ampm)
        
    GUICtrlSetData($VPNDOWNTIME,$VPNDOWN)
    If $VPNSOUNDBIT = "" then
    SoundPlay("VPNDOWN.wav",1)
    $VPNSOUNDBIT = "1"
    EndIf
    ElseIf $VPNDOWNBIT = "1" then
        $var2 = Ping($VPNHop, 250)
        If $var2 > 1 then
            $VPNUPBIT = "1"
            if @hour = "12" then
                $hour = @hour
                $ampm = "PM"
            ElseIf @hour >= "13" then
                $hour = @hour - 12
                $ampm = "PM"
            ElseIf @hour < "12" then
                $hour = @hour
                $ampm = "AM"
            ElseIf @hour = 0 then
                $hour = 12 + @hour
                $ampm = "AM"
            EndIF
            If $VPNUP = "" then $VPNUP = ($hour&":"&@min&" "&$ampm)

            GUICtrlSetData($VPNUPTIME,$VPNUP)
            SoundPlay("VPNUP.wav",1)
            FileWriteLine($file, @MON & "/" & @MDAY & "/" & @YEAR & @CRLF)
            FileWriteLine($file, "VPN went down at: "& $VPNDOWN & @CRLF)
            FileWriteLine($file, "VPN came up at: "& $VPNUP & @CRLF)
        ENDIF


    GUICtrlSetData($vpnstatus,"Connected")
    GUICtrlSetBkColor($vpnstatus, 0x00FF00)
    EndIf

    
    $var = Ping($1stHop, 250)
    
    If $var < 1  Then
    GUICtrlSetData($1stHopstatus,"")
    Sleep (200)
    GUICtrlSetData($1stHopstatus,"    Down")
    GUICtrlSetBkColor($1stHopstatus, 0xFF0000)
    Sleep (200)
    $1stHopDown = "Can't connect to 1st Hop "&$1stHop
    FileWriteLine($file, $1stHopDown & @CRLF)

    Else
    GUICtrlSetData($1stHopstatus,"Connected")
    GUICtrlSetBkColor($1stHopstatus, 0x00FF00)
    EndIf

    $var1 = Ping($INETHop, 250)

    If $var1 < 1 Then
    $INETDOWNBIT = "1"
    GUICtrlSetData($inetstatus,"")
    Sleep (200)
    GUICtrlSetData($inetstatus,"    Down")
    GUICtrlSetBkColor($inetstatus, 0xFF0000)
    Sleep (200)
    GUISetFont(10, 400, 0, $font1)
    if @hour = "12" then
        $hour = @hour
        $ampm = "PM"
    ElseIf @hour >= "13" then
        $hour = @hour - 12
        $ampm = "PM"
    ElseIf @hour < "12" then
        $hour = @hour
        $ampm = "AM"
    ElseIf @hour = 0 then
        $hour = 12 + @hour
        $ampm = "AM"
    EndIF
    If $INETDOWN = "" then $INETDOWN = ($hour&":"&@min&" "&$ampm)
    GUICtrlSetData($INETDOWNTIME,$INETDOWN)
    If $INETSOUNDBIT = "" then
    SoundPlay("INETDOWN.wav",1)
    $INETSOUNDBIT = "1"
    ENDIf
    ElseIf $INETDOWNBIT = "1" then
        $var3 = Ping($INETHop, 250)
        If $var3 > 1 then
            $INETUPBIT = "1"
            if @hour = "12" then
                $hour = @hour
                $ampm = "PM"
            ElseIf @hour >= "13" then
                $hour = @hour - 12
                $ampm = "PM"
            ElseIf @hour < "12" then
                $hour = @hour
                $ampm = "AM"
            ElseIf @hour = 0 then
                $hour = 12 + @hour
                $ampm = "AM"
            EndIF
            If $INETUP = "" then $INETUP = ($hour&":"&@min&" "&$ampm)
            GUICtrlSetData($INETUPTIME,$INETUP)
            SoundPlay("INETUP.wav",1)
            FileWriteLine($file, "Internet went down at: "& $INETDOWN & @CRLF)
            FileWriteLine($file, "Internet came up at: "& $INETUP & @CRLF)
        EndIf
    
    GUICtrlSetData($inetstatus,"Connected")
    GUICtrlSetBkColor($inetstatus, 0x00FF00)
    ENDIF

    If $VPNDOWNBIT = "1" then
        IF $VPNUPBIT = "1" then
            GUISetState (@SW_SHOW)
            $s_SmtpServer = $SMTPServer
            $s_FromName = $Location
            $s_FromAddress = $Email
            $s_ToAddress = $Email
            $s_Subject = "Connection Status"
            Dim $as_Body[5]
            $as_Body[0] = "VPN went down at: "& $VPNDOWN
            $as_Body[1] = "Internet went down at: "&$INETDOWN
            $as_Body[2] = $1stHopDown
            $as_Body[3] = "VPN came back up at: "&$VPNUP
            $as_Body[4] = "Internet came back up at: "&$INETUP
            $Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
            $err = @error
                If $Response = 1 Then
                MsgBox(0, "Email Sent", "                    Connections have been reestablished."&@CRLF&"An Email has been sent to Terry letting him know what happened.")
                Else
                    MsgBox(0, "Error!", "Mail failed with error code " & $err)
                EndIf           

            $VPNDOWN = ""
            $VPNUP = ""
            $INETDOWN = ""
            $INETUP = ""
            $VPNDOWNBIT = ""
            $VPNUPBIT = ""
            $VPNSOUNDBIT = ""
            $INETSOUNDBIT = ""
            $INETDOWNBIT = ""
            GUISetState (@SW_HIDE)
        EndIF
    EndIF

WEnd

Func SpecialEvents()
    Select
        Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE
            GUISetState (@SW_HIDE)
        Case @GUI_CTRLID = $GUI_EVENT_CLOSE
            MsgBox(0, "Close pressed", "         You're trying to close this window."&@CRLF&@CRLF&"Sorry, but this program needs to keep running.")
;           Exit
    EndSelect
EndFunc

Func Minimized_button_pressed()
    GUISetState (@SW_HIDE)
EndFunc
Posted

did you ever thing that your labels WERE HUGE, the last paramater 60 is way to big its overlapping with the button there for u cant do anything with it , with ur internet status one the label above the button change it to 20 at the end not 60 and as for it not working im still trying to figure that one out xD

Posted

GUICtrlCreateLabel("Last VPN Drop", 60, 260, 190, 60)
GUICtrlCreateLabel("Last Internet Drop", 60, 280, 190, 60)
GUICtrlCreateLabel("VPN Re-established", 60, 300, 190, 60)
GUICtrlCreateLabel("Internet Re-established", 60, 320, 190, 60)

Found the problem with the button not highlighting properly. It appears that WIDTH of the above labels were much too big for the font size I choose. The extra size was encroaching on the buttons location. I found this out because I moved $button_min = GUICtrlCreateButton('Minimize Window', 110, 360, 180, 23) line to right underneath the GUICreate line and when run you could see a blank area over the button, but as soon as you highlighted the button the blank area would go away. So I simply moved the GUICtrlCreateButton line down every few lines in the code until I found where it was showing up without the blank area covering it. I then looked at the code above and noticed that the size of the label (height) was way to large.

Posted

Yep, thanks Thatsgreat2345. I also noticed that I was using the wrong function. Again, I'm a noob. :P Thanks for the help. I've learned alot.

Stupid mistakes. Just stupid, but hey I'm used to using DOS batch files. I'm very new to this type of programming.

Posted

Thatsgreat2345

Ok, after playing with the code a bit more and reading, re-reading the help file as well as seeing some examples I got it working. Very nice, it's flashing better without the other color glitch. It also made me changing some settings a little easier. I corrected the Variable problem as well as the font problem, at least hopefully I corrected it. Thanks for the suggestions.. :P

Any suggestions on how I'd start on that?

Here's the revised code:

#include <GuiConstants.au3>
#include <GuiListView.au3>
#include<date.au3>
#include <INet.au3>
Global $Sec, $Min, $Hour, $Time

GUICreate("Connection Monitor", 400, 400)

;GUISetIcon("SHELL32.dll", 18)
$font = "Arial Black"
$font1 = "Arial"
$VPNDOWN = ""
$INETDOWN = ""
$VPNUP = ""
$INETUP = ""
$VPNDOWNBIT = ""
$VPNUPBIT = ""
$INETDOWNBIT = ""
$INETUPBIT = ""
$VPNSOUNDBIT = ""
$INETSOUNDBIT = ""
$1stHopDown = ""

;Import INI settings
$Location = IniRead("settings.ini", "Settings", "Location", "")
$VPNHop = IniRead("settings.ini", "Settings", "VPNHop", "")
$1stHop = IniRead("settings.ini", "Settings", "1stHop", "")
$INETHop = IniRead("settings.ini", "Settings", "INETHop", "")
$SMTPServer = IniRead("settings.ini", "Settings", "SMTPServer", "")
$Email = IniRead("settings.ini", "Settings", "Email", "")

;Labels
$vpnstatus    = GUICtrlCreateLabel("", 240, 90, 125, 32)
$1sthopstatus = GUICtrlCreateLabel("", 240, 140, 125, 32)
$inetstatus   = GUICtrlCreateLabel("", 240, 190, 125, 32)
$VPNDOWNTIME  = GUICtrlCreateLabel("", 280, 260, 90, 40)
$INETDOWNTIME = GUICtrlCreateLabel("", 280, 280, 90, 40)
$VPNUPTIME    = GUICtrlCreateLabel("", 280, 300, 90, 40)
$INETUPTIME   = GUICtrlCreateLabel("", 280, 320, 90, 40)
; Show the GUI
;GUISetFont(16, 400, 0, $font)
GUICtrlSetFont ($vpnstatus,16, 400, 0, $font)
GUICtrlSetFont ($1stHopstatus,16, 400, 0, $font)
GUICtrlSetFont ($inetstatus,16, 400, 0, $font)
GUICtrlSetFont ($VPNDOWNTIME,10, 400, 0, $font1)
GUICtrlSetFont ($VPNUPTIME,10, 400, 0, $font1)
GUICtrlSetFont ($INETDOWNTIME,10, 400, 0, $font1)
GUICtrlSetFont ($INETUPTIME,10, 400, 0, $font1)
GUICtrlSetFont ($VPNDOWN,10, 400, 0, $font1)
GUICtrlSetFont ($VPNUP,10, 400, 0, $font1)
GUICtrlSetFont ($INETDOWN,10, 400, 0, $font1)
GUICtrlSetFont ($INETUP,10, 400, 0, $font1)

GUISetFont(16, 400, 0, $font)
GUICtrlCreateLabel("VPN Status", 25, 90, 190, 60)
GUICtrlSetData($vpnstatus,"Connected")
GUICtrlSetBkColor($vpnstatus, 0x00FF00)
GUICtrlCreateLabel("1st Hop Status", 25, 140, 190, 60)
GUICtrlSetData($1stHopstatus,"Connected")
GUICtrlSetBkColor($1stHopstatus, 0x00FF00)
GUICtrlCreateLabel("Internet Status", 25, 190, 190, 60)
GUICtrlSetData($inetstatus,"Connected")
GUICtrlSetBkColor($inetstatus, 0x00FF00)

;Show images
;GUICtrlCreatePic("Green-Arrow.gif", 60, 20, 50, 50)
;Time listings
;$vpndowntime = "N/A"
;$inetdowntime = "N/A"
GUISetFont(10, 400, 0, $font1)
GUICtrlCreateLabel("Last VPN Drop", 60, 260, 190, 60)
GUICtrlCreateLabel("Last Internet Drop", 60, 280, 190, 60)
GUICtrlCreateLabel("VPN Re-established", 60, 300, 190, 60)
GUICtrlCreateLabel("Internet Re-established", 60, 320, 190, 60)
GUISetFont(9, 400, 0, $font1)
$button_min = GUICtrlCreateButton('Minimize Window', 110, 360, 180, 23)
GUISetState (@SW_HIDE)
While 1

    $msg = GUIGetMsg()

    Select
        Case $msg = $button_min
        GUISetState (@SW_HIDE)
        Case $msg = $GUI_EVENT_CLOSE
        Exit
    EndSelect

    $var = Ping($VPNHop, 250)
    
    If $var < 1  Then
    GUISetState (@SW_SHOW)
    $VPNDOWNBIT = "1"
        GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($vpnstatus,"")
    Sleep (250)
    GUICtrlSetData($vpnstatus,"    Down")
        GUICtrlSetBkColor($vpnstatus, 0xFF0000)
    Sleep (250)
    GUISetFont(10, 400, 0, $font1)
    if @hour = "12" then
        $hour = @hour
        $ampm = "PM"
    EndIf
    if @hour >= "13" then
        $hour = @hour - 12
        $ampm = "PM"
    EndIF
    if @hour < "12" then
        $hour = @hour
        $ampm = "AM"
    EndIF
    if @hour = 0 then
        $hour = 12 + @hour
        $ampm = "AM"
    EndIF
    If $VPNDOWN = "" then
        $VPNDOWN = ($hour&":"&@min&" "&$ampm)
    EndIf
    GUICtrlSetData($VPNDOWNTIME,$VPNDOWN)
    If $VPNSOUNDBIT = "" then
    SoundPlay("VPNDOWN.wav",1)
    $VPNSOUNDBIT = "1"
    ENDIf
    Else
    If $VPNDOWNBIT = "1" then
        $var2 = Ping($VPNHop, 250)
        If $var2 > 1 then
            $VPNUPBIT = "1"
            if @hour = "12" then
                $hour = @hour
                $ampm = "PM"
            EndIf
            if @hour >= "13" then
                $hour = @hour - 12
                $ampm = "PM"
            EndIF
            if @hour < "12" then
                $hour = @hour
                $ampm = "AM"
            EndIF
            if @hour = 0 then
                $hour = 12 + @hour
                $ampm = "AM"
            EndIF
            If $VPNUP = "" then
                $VPNUP = ($hour&":"&@min&" "&$ampm)
            EndIf

            GUICtrlSetData($VPNUPTIME,$VPNUP)

            SoundPlay("VPNUP.wav",1)
            $file = FileOpen("Connection.log", 1)
            FileWriteLine($file, @MON & "/" & @MDAY & "/" & @YEAR & @CRLF)
            FileWriteLine($file, "VPN went down at: "& $VPNDOWN & @CRLF)
            FileWriteLine($file, "VPN came up at: "& $VPNUP & @CRLF)
            FileClose($file)
        EndIf
    ENDIF
        GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($vpnstatus,"Connected")
    GUICtrlSetBkColor($vpnstatus, 0x00FF00)
    EndIf
    $var = Ping($1stHop, 250)
    
    If $var < 1  Then
        GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($1stHopstatus,"")
    Sleep (250)
    GUICtrlSetData($1stHopstatus,"    Down")
        GUICtrlSetBkColor($1stHopstatus, 0xFF0000)
    Sleep (250)
    $1stHopDown = "Can't connect to 1st Hop "&$1stHop
    $file = FileOpen("Connection.log", 1)
    FileWriteLine($file, $1stHopDown & @CRLF)
    FileClose($file)

    Else
        GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($1stHopstatus,"Connected")
    GUICtrlSetBkColor($1stHopstatus, 0x00FF00)
    EndIf
    $var1 = Ping($INETHop, 250)

    If $var1 < 1 Then
    $INETDOWNBIT = "1"
        GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($inetstatus,"")
    Sleep (250)
    GUICtrlSetData($inetstatus,"    Down")
        GUICtrlSetBkColor($inetstatus, 0xFF0000)
    Sleep (250)
    GUISetFont(10, 400, 0, $font1)
    if @hour = "12" then
        $hour = @hour
        $ampm = "PM"
    EndIf
    if @hour >= "13" then
        $hour = @hour - 12
        $ampm = "PM"
    EndIF
    if @hour < "12" then
        $hour = @hour
        $ampm = "AM"
    EndIF
    if @hour = 0 then
        $hour = 12 + @hour
        $ampm = "AM"
    EndIF
    If $INETDOWN = "" then
        $INETDOWN = ($hour&":"&@min&" "&$ampm)
    EndIf
    GUICtrlSetData($INETDOWNTIME,$INETDOWN)
    If $INETSOUNDBIT = "" then
    SoundPlay("INETDOWN.wav",1)
    $INETSOUNDBIT = "1"
    ENDIf
    Else
    If $INETDOWNBIT = "1" then
        $var3 = Ping($INETHop, 250)
        If $var3 > 1 then
            $INETUPBIT = "1"
            if @hour = "12" then
                $hour = @hour
                $ampm = "PM"
            EndIf
            if @hour >= "13" then
                $hour = @hour - 12
                $ampm = "PM"
            EndIF
            if @hour < "12" then
                $hour = @hour
                $ampm = "AM"
            EndIF
            if @hour = 0 then
                $hour = 12 + @hour
                $ampm = "AM"
            EndIF
            If $INETUP = "" then
                $INETUP = ($hour&":"&@min&" "&$ampm)
            EndIf
            GUICtrlSetData($INETUPTIME,$INETUP)
            SoundPlay("INETUP.wav",1)
            $file = FileOpen("Connection.log", 1)
            FileWriteLine($file, "Internet went down at: "& $INETDOWN & @CRLF)
            FileWriteLine($file, "Internet came up at: "& $INETUP & @CRLF)
            FileClose($file)
        EndIf
    ENDIF
        GUISetFont(18, 400, 0, $font)
    GUICtrlSetData($inetstatus,"Connected")
    GUICtrlSetBkColor($inetstatus, 0x00FF00)
    EndIf

    If $VPNDOWNBIT = "1" then
        IF $VPNUPBIT = "1" then
            GUISetState (@SW_SHOW)
            $s_SmtpServer = $SMTPServer
            $s_FromName = $Location
            $s_FromAddress = $Email
            $s_ToAddress = $Email
            $s_Subject = "Connection Status"
            Dim $as_Body[5]
            $as_Body[0] = "VPN went down at: "& $VPNDOWN
            $as_Body[1] = "Internet went down at: "&$INETDOWN
            $as_Body[2] = $1stHopDown
            $as_Body[3] = "VPN came back up at: "&$VPNUP
            $as_Body[4] = "Internet came back up at: "&$INETUP
            $Response = _INetSmtpMail ($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body)
            $err = @error
                If $Response = 1 Then
                MsgBox(0, "Email Sent", "                    Connections have been reestablished."& @CRLF&"An Email has been sent to Terry letting him know what happened.")
                Else
                    MsgBox(0, "Error!", "Mail failed with error code " & $err)
                EndIf           

            $VPNDOWN = ""
            $VPNUP = ""
            $INETDOWN = ""
            $INETUP = ""
            $VPNDOWNBIT = ""
            $VPNUPBIT = ""
            $VPNSOUNDBIT = ""
            $INETSOUNDBIT = ""
            $INETDOWNBIT = ""
        EndIF
    EndIF

WEnd
You can shorten the @Hour code by using

If @Hour <= 11 Then

$AmPm = "AM"

Else

$AmPm = "PM

EndIf

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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
  • Recently Browsing   0 members

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