Sign in to follow this  
Followers 0
gcue

how to create a status section within gui

14 posts in this topic

hello all.

i have a script that does some pinging on devices specified by the user. id like to add a section in the gui that shows the status of what its doing..

im sure its possible just dunno how to do it - any help is appreciated - thanks!

here's what the gui looks like

parent = GUICreate("Device Pinger v0.1", 275, 200)


$filemenu = GUICtrlCreateMenu ("&File")

$fileitem = GUICtrlCreateMenuitem ("Ping Devices",$filemenu)
GUICtrlSetOnEvent(-1,"PingDevices")

$fileitem = GUICtrlCreateMenuitem ("Edit Device List",$filemenu)
GUICtrlSetOnEvent(-1,"EditCSV")

$fileitem = GUICtrlCreateMenuitem ("Export Status to CSV",$filemenu)
GUICtrlSetOnEvent(-1,"ExportCSV")

$helpmenu = GUICtrlCreateMenu ("&Help")
$helpitem = GUICtrlCreateMenuitem ("About",$helpmenu)
GUICtrlSetOnEvent(-1,"About")

GUISetOnEvent($GUI_EVENT_CLOSE, "XButton")

;$background = GUICtrlCreatePic ("pong.jpg", 110, 0, 100, 46)

GUISetState(@SW_SHOW)

While 1
  Sleep(1000)
WEndoÝ÷ Ù©ÝêÞ³Z¶Êîx§)íæÚrH+¢éÝjëh×6Func PingDevices()


If FileExists(@TempDir & "\status.csv") Then
    FileDelete (@TempDir & "\status.csv")
    FileWrite($statusfile, "Location, Device, Status")
EndIf


Local $location, $L, $device, $d
$location = IniReadSectionNames(@UserName & "\devices.ini")
If IsArray($location) Then
    For $L = 1 To $location[0]
        $device = IniReadSection(@UserName & "\devices.ini", $location[$L])
        If IsArray($device) Then
            For $d = 1 To $device[0][0]

Ping($device[$d][1])

    If @error Then
     $status="OFFLINE"
    EndIf

    If Not @error Then
     $status="ONLINE"
    EndIf
 
FileWrite($statusfile, '' &@CRLF & _
                 $location[$L] & "," & $device[$d][0] & "," & $status) 

           Next
        Else
            MsgBox(16, "Error", "There was an error reading section: " & $location[$L] & @CRLF & "Section Number was: " & $L)
        EndIf
    Next
Else
    MsgBox(16, "", "Error occurred, probably no INI file.")
EndIf
EndFunc

Share this post


Link to post
Share on other sites



#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#Include <GuiStatusBar.au3>

Dim $statusfile

$parent = GUICreate("Device Pinger v0.1", 275, 200)


$filemenu = GUICtrlCreateMenu ("&File")

$fileitem = GUICtrlCreateMenuitem ("Ping Devices",$filemenu)
GUICtrlSetOnEvent(-1,"PingDevices")

$fileitem = GUICtrlCreateMenuitem ("Edit Device List",$filemenu)
;GUICtrlSetOnEvent(-1,"EditCSV")

$fileitem = GUICtrlCreateMenuitem ("Export Status to CSV",$filemenu)
;GUICtrlSetOnEvent(-1,"ExportCSV")

$helpmenu = GUICtrlCreateMenu ("&Help")
$helpitem = GUICtrlCreateMenuitem ("About",$helpmenu)
;GUICtrlSetOnEvent(-1,"About")

$hStatus = _GUICtrlStatusBar_Create ($parent, 100, "This is a status bar")


;GUISetOnEvent($GUI_EVENT_CLOSE, "XButton")

;$background = GUICtrlCreatePic ("pong.jpg", 110, 0, 100, 46)

GUISetState(@SW_SHOW)

While 1
  Sleep(1000)
WEnd

see status bar in help for further info

8)


NEWHeader1.png

Share this post


Link to post
Share on other sites

ahh actually what i meant was status like this:

---------status--------------

pinging device 1 ... Online

pinging device 2 ... offline

and if it gets too long where itd automatically create scroll within the window.

Share this post


Link to post
Share on other sites

Just add an edit control maybe.


My UDFs: ExitCodes

Share this post


Link to post
Share on other sites

edit control?

Just add an edit control maybe.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Added a View > Status menu so that you can check or uncheck whether or not you want the status label to appear

Added a case code for the View > status menu

Created a status label for you (you need to update the location in your GUI (usually at the bottom is a good place as it has a sunken appearance)

Added an update to your ping function

Check all the NEW CODE remarks

Updated this to counter the fact that no global variables were defined and in this case they shouldn't have to be. So, initial label is set with a short statement.

$parent = GUICreate("Device Pinger v0.1", 275, 200)
$filemenu = GUICtrlCreateMenu("&File")
$fileitem = GUICtrlCreateMenuItem("Ping Devices", $filemenu)
GUICtrlSetOnEvent(-1, "PingDevices")
$fileitem = GUICtrlCreateMenuItem("Edit Device List", $filemenu)
GUICtrlSetOnEvent(-1, "EditCSV")
$fileitem = GUICtrlCreateMenuItem("Export Status to CSV", $filemenu)
GUICtrlSetOnEvent(-1, "ExportCSV")

; setup a view menu with status checked so users can check/uncheck status
; NEW CODE
$viewmenu = GUICtrlCreateMenu("View", -1, 2)
$viewstatusitem = GUICtrlCreateMenuItem("Statusbar", $viewmenu)
GUICtrlSetState($viewstatusitem, $GUI_CHECKED)

$helpmenu = GUICtrlCreateMenu("&Help")
$helpitem = GUICtrlCreateMenuItem("About", $helpmenu)
GUICtrlSetOnEvent(-1, "About")

GUISetOnEvent($GUI_EVENT_CLOSE, "XButton")

; create your status label and place it where you want in your GUI
; NEW CODE
$statuslabel = GUICtrlCreateLabel("No Devices Pinged Yet" , 119, 590, 129, 17, BitOR($SS_SIMPLE, $SS_SUNKEN))

GUISetState(@SW_SHOW)

While 1
    Sleep(1000)
        ; NEW CODE - assuming you are running ping somewhere in the code and updating the status label under view if you want to show/hide it.
    PingDevices()
    Select
        Case $msg = $viewstatusitem
            If BitAND(GUICtrlRead($viewstatusitem), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($viewstatusitem, $GUI_UNCHECKED)
                GUICtrlSetState($statuslabel, $GUI_HIDE)
            Else
                GUICtrlSetState($viewstatusitem, $GUI_CHECKED)
                GUICtrlSetState($statuslabel, $GUI_SHOW)
            EndIf
    EndSelect
WEnd

Func PingDevices()


    If FileExists(@TempDir & "\status.csv") Then
        FileDelete(@TempDir & "\status.csv")
        FileWrite($statusfile, "Location, Device, Status")
    EndIf


    Local $location, $L, $device, $d
    $location = IniReadSectionNames(@UserName & "\devices.ini")
    If IsArray($location) Then
        For $L = 1 To $location[0]
            $device = IniReadSection(@UserName & "\devices.ini", $location[$L])
            If IsArray($device) Then
                For $d = 1 To $device[0][0]

                    Ping($device[$d][1])

                    If @error Then
                        $status = "OFFLINE"
                    EndIf

                    If Not @error Then
                        $status = "ONLINE"
                    EndIf
                    ; Update the status label
                    ; NEW CODE
                    GUICtrlSetData($statuslabel, " " & $location[$L] & ", " & $device[$d][0] & " = " & $status)
                    FileWrite($statusfile, '' & @CRLF & _
                            $location[$L] & "," & $device[$d][0] & "," & $status)

                Next
            Else
                MsgBox(16, "Error", "There was an error reading section: " & $location[$L] & @CRLF & "Section Number was: " & $L)
            EndIf
        Next
    Else
        MsgBox(16, "", "Error occurred, probably no INI file.")
    EndIf
EndFunc   ;==>PingDevices
Edited by Ealric

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Share this post


Link to post
Share on other sites

Updated the post above - you should be able to make use of it now.


My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Share this post


Link to post
Share on other sites

thanks for your help!!

i cant find where the undeclared variable is..

Opt("GUIOnEventMode", 1)
#Include <GuiConstants.au3>
#Include <Constants.au3>
#include <file.au3>


If Not FileExists ("\" & @UserName) Then
  DirCreate(@UserName)
EndIf

$devicesfile = @UserName & "\devices.ini"

If Not FileExists (@UserName & "\devices.ini") Then
  FileWrite($devicesfile, "[CRGI Trading Room]" &@CRLF & _
                          "LAO-53-TRADING4-HP4650DN=10.60.21.220" &@CRLF & _
                          "" &@CRLF & _
                          "[CWI Trading Room]" &@CRLF & _
                          "LAO-34-E-CWI-TRADING3-HP4350DTN=10.60.10.223" &@CRLF & _
                          "HP Digital Sender 9200C=10.60.10.224")
EndIf

$statusfile = @TempDir & "\status.csv"

If FileExists(@TempDir & "\status.csv") Then
    FileDelete (@TempDir & "\status.csv")
EndIf

If FileExists(@UserName & "\status.csv") Then
    FileDelete (@UserName & "\status.csv")
EndIf

FileWrite($statusfile, "Location, Device, Status")




$parent = GUICreate("Device Pinger v0.1", 275, 200)


$filemenu = GUICtrlCreateMenu ("&File")

$fileitem = GUICtrlCreateMenuitem ("Ping Devices",$filemenu)
GUICtrlSetOnEvent(-1,"PingDevices")

$fileitem = GUICtrlCreateMenuitem ("Edit Device List",$filemenu)
GUICtrlSetOnEvent(-1,"EditCSV")

$fileitem = GUICtrlCreateMenuitem ("Export Status to CSV",$filemenu)
GUICtrlSetOnEvent(-1,"ExportCSV")

$viewmenu = GUICtrlCreateMenu("View", -1, 2)
$viewstatusitem = GUICtrlCreateMenuItem("Statusbar", $viewmenu)
GUICtrlSetState($viewstatusitem, $GUI_CHECKED)

$helpmenu = GUICtrlCreateMenu ("&Help")
$helpitem = GUICtrlCreateMenuitem ("About",$helpmenu)
GUICtrlSetOnEvent(-1,"About")

GUISetOnEvent($GUI_EVENT_CLOSE, "XButton")

$statuslabel = GUICtrlCreateLabel("No Devices Pinged Yet" , 119, 590, 129, 17, BitOR($SS_SIMPLE, $SS_SUNKEN))


;$background = GUICtrlCreatePic ("pong.jpg", 110, 0, 100, 46)

GUISetState(@SW_SHOW)

While 1
  Sleep(1000)
  PingDevices()
    Select
        Case $msg = $viewstatusitem
            If BitAND(GUICtrlRead($viewstatusitem), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($viewstatusitem, $GUI_UNCHECKED)
                GUICtrlSetState($statuslabel, $GUI_HIDE)
            Else
                GUICtrlSetState($viewstatusitem, $GUI_CHECKED)
                GUICtrlSetState($statuslabel, $GUI_SHOW)
            EndIf
    EndSelect
WEnd



Func PingDevices()


If FileExists(@TempDir & "\status.csv") Then
    FileDelete (@TempDir & "\status.csv")
    FileWrite($statusfile, "Location, Device, Status")
EndIf


Local $location, $L, $device, $d
$location = IniReadSectionNames(@UserName & "\devices.ini")
If IsArray($location) Then
    For $L = 1 To $location[0]
        $device = IniReadSection(@UserName & "\devices.ini", $location[$L])
        If IsArray($device) Then
            For $d = 1 To $device[0][0]

Ping($device[$d][1])

    If @error Then
     $status="OFFLINE"
    EndIf

    If Not @error Then
     $status="ONLINE"
    EndIf

GUICtrlSetData($statuslabel, " " & $location[$L] & ", " & $device[$d][0] & " = " & $status)

FileWrite($statusfile, '' &@CRLF & _
                 $location[$L] & "," & $device[$d][0] & "," & $status) 

           Next
        Else
            MsgBox(16, "Error", "There was an error reading section: " & $location[$L] & @CRLF & "Section Number was: " & $L)
        EndIf
    Next
Else
    MsgBox(16, "", "Error occurred, probably no INI file.")
EndIf
EndFunc


Func EditCSV()
 ShellExecute(@UserName & "\devices.ini")
EndFunc

Func ExportCSV()
$csvfile = FileSaveDialog ( "Export CSV", @UserProfileDir & "\Desktop", "Comma Seperated Values (*.csv)", 16)
 FileCopy(@TempDir & "\status.csv", $csvfile & ".csv", 1)
 ShellExecute($csvfile & ".csv")
EndFunc

Func About()
MsgBox(262208, "About", 'Device Pinger v0.1'&@CRLF & _
                        ''&@CRLF & _
                        'Pings devices in: ' & @UserName & '\devices.ini'&@CRLF & _
                        '(You can add as many locations/devices as you want.)'&@CRLF & _
                        ''&@CRLF & _
                        'Contact GXM x90760 for questions/suggestions.')
EndFunc


Func Xbutton()
  FileDelete(@TempDir & "\status.csv")
  Exit
EndFunc

Updated the post above - you should be able to make use of it now.

Share this post


Link to post
Share on other sites

Here you go.

Opt("GUIOnEventMode", 1)
#include <GuiConstants.au3>
#include <Constants.au3>
#include <file.au3>


If Not FileExists("\" & @UserName) Then
    DirCreate(@UserName)
EndIf

$devicesfile = @UserName & "\devices.ini"

If Not FileExists(@UserName & "\devices.ini") Then
    FileWrite($devicesfile, "[CRGI Trading Room]" & @CRLF & _
            "LAO-53-TRADING4-HP4650DN=10.60.21.220" & @CRLF & _
            "" & @CRLF & _
            "[CWI Trading Room]" & @CRLF & _
            "LAO-34-E-CWI-TRADING3-HP4350DTN=10.60.10.223" & @CRLF & _
            "HP Digital Sender 9200C=10.60.10.224")
EndIf

$statusfile = @TempDir & "\status.csv"

If FileExists(@TempDir & "\status.csv") Then
    FileDelete(@TempDir & "\status.csv")
EndIf

If FileExists(@UserName & "\status.csv") Then
    FileDelete(@UserName & "\status.csv")
EndIf

FileWrite($statusfile, "Location, Device, Status")

$parent = GUICreate("Device Pinger v0.1", 275, 200)

$filemenu = GUICtrlCreateMenu("&File")

$filepingitem = GUICtrlCreateMenuItem("Ping Devices", $filemenu)
GUICtrlSetOnEvent(-1, "PingDevices")

$fileedititem = GUICtrlCreateMenuItem("Edit Device List", $filemenu)
GUICtrlSetOnEvent(-1, "EditCSV")

$fileexportitem = GUICtrlCreateMenuItem("Export Status to CSV", $filemenu)
GUICtrlSetOnEvent(-1, "ExportCSV")

$viewmenu = GUICtrlCreateMenu("View", -1, 2)
$viewstatusitem = GUICtrlCreateMenuItem("Statusbar", $viewmenu)
GUICtrlSetState($viewstatusitem, $GUI_CHECKED)

$helpmenu = GUICtrlCreateMenu("&Help")
$helpitem = GUICtrlCreateMenuItem("About", $helpmenu)
GUICtrlSetOnEvent(-1, "About")

GUISetOnEvent($GUI_EVENT_CLOSE, "XButton")

$statuslabel = GUICtrlCreateLabel("No Devices Pinged Yet",0,160,275,20,BitOR($SS_SIMPLE,$SS_SUNKEN))

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Sleep(0300)
    Select
        Case $msg = $viewstatusitem
            If BitAND(GUICtrlRead($viewstatusitem), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($viewstatusitem, $GUI_UNCHECKED)
                GUICtrlSetState($statuslabel, $GUI_HIDE)
            Else
                GUICtrlSetState($viewstatusitem, $GUI_CHECKED)
                GUICtrlSetState($statuslabel, $GUI_SHOW)
            EndIf
        Case $msg = $filepingitem
            PingDevices()
        Case $msg = $fileedititem
            EditCSV()
        Case $msg = $fileexportitem
            ExportCSV()
        Case $msg = $helpitem
            About()
        Case $msg = $GUI_EVENT_CLOSE 
            Xbutton()
    EndSelect
WEnd



Func PingDevices()


    If FileExists(@TempDir & "\status.csv") Then
        FileDelete(@TempDir & "\status.csv")
        FileWrite($statusfile, "Location, Device, Status")
    EndIf


    Local $location, $L, $device, $d
    $location = IniReadSectionNames(@UserName & "\devices.ini")
    If IsArray($location) Then
        For $L = 1 To $location[0]
            $device = IniReadSection(@UserName & "\devices.ini", $location[$L])
            If IsArray($device) Then
                For $d = 1 To $device[0][0]

                    Ping($device[$d][1])

                    If @error Then
                        $status = "OFFLINE"
                    EndIf

                    If Not @error Then
                        $status = "ONLINE"
                    EndIf

                    GUICtrlSetData($statuslabel, " " & $location[$L] & ", " & $device[$d][0] & " = " & $status)

                    FileWrite($statusfile, '' & @CRLF & _
                            $location[$L] & "," & $device[$d][0] & "," & $status)

                Next
            Else
                MsgBox(16, "Error", "There was an error reading section: " & $location[$L] & @CRLF & "Section Number was: " & $L)
            EndIf
        Next
    Else
        MsgBox(16, "", "Error occurred, probably no INI file.")
    EndIf
EndFunc   ;==>PingDevices


Func EditCSV()
    ShellExecute(@UserName & "\devices.ini")
EndFunc   ;==>EditCSV

Func ExportCSV()
    $csvfile = FileSaveDialog("Export CSV", @UserProfileDir & "\Desktop", "Comma Seperated Values (*.csv)", 16)
    FileCopy(@TempDir & "\status.csv", $csvfile & ".csv", 1)
    ShellExecute($csvfile & ".csv")
EndFunc   ;==>ExportCSV

Func About()
    MsgBox(262208, "About", 'Device Pinger v0.1' & @CRLF & _
            '' & @CRLF & _
            'Pings devices in: ' & @UserName & '\devices.ini' & @CRLF & _
            '(You can add as many locations/devices as you want.)' & @CRLF & _
            '' & @CRLF & _
            'Contact GXM x90760 for questions/suggestions.')
EndFunc   ;==>About


Func Xbutton()
    FileDelete(@TempDir & "\status.csv")
    Exit
EndFunc   ;==>Xbutton
Um... :)

You may have fixed the undeclared variable, but you haven't fixed an issue of not being able to use GUIGetMsg() and GUIOnEventMode together :)


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Here, use this instead:

#include <GuiConstants.au3>
#include <Constants.au3>
#include <file.au3>


If Not FileExists("\" & @UserName) Then
    DirCreate(@UserName)
EndIf

$devicesfile = @UserName & "\devices.ini"

If Not FileExists(@UserName & "\devices.ini") Then
    FileWrite($devicesfile, "[CRGI Trading Room]" & @CRLF & _
            "LAO-53-TRADING4-HP4650DN=10.60.21.220" & @CRLF & _
            "" & @CRLF & _
            "[CWI Trading Room]" & @CRLF & _
            "LAO-34-E-CWI-TRADING3-HP4350DTN=10.60.10.223" & @CRLF & _
            "HP Digital Sender 9200C=10.60.10.224")
EndIf

$statusfile = @TempDir & "\status.csv"

If FileExists(@TempDir & "\status.csv") Then
    FileDelete(@TempDir & "\status.csv")
EndIf

If FileExists(@UserName & "\status.csv") Then
    FileDelete(@UserName & "\status.csv")
EndIf

FileWrite($statusfile, "Location, Device, Status")

$parent = GUICreate("Device Pinger v0.1", 275, 200)

$filemenu = GUICtrlCreateMenu("&File")
$filepingitem = GUICtrlCreateMenuItem("Ping Devices", $filemenu)
$fileedititem = GUICtrlCreateMenuItem("Edit Device List", $filemenu)
$fileexportitem = GUICtrlCreateMenuItem("Export Status to CSV", $filemenu)
$viewmenu = GUICtrlCreateMenu("View", -1, 2)
$viewstatusitem = GUICtrlCreateMenuItem("Statusbar", $viewmenu)
GUICtrlSetState($viewstatusitem, $GUI_CHECKED)
$helpmenu = GUICtrlCreateMenu("&Help")
$helpitem = GUICtrlCreateMenuItem("About", $helpmenu)
$statuslabel = GUICtrlCreateLabel("No Devices Pinged Yet",0,160,275,20,BitOR($SS_SIMPLE,$SS_SUNKEN))

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $viewstatusitem
            If BitAND(GUICtrlRead($viewstatusitem), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($viewstatusitem, $GUI_UNCHECKED)
                GUICtrlSetState($statuslabel, $GUI_HIDE)
            Else
                GUICtrlSetState($viewstatusitem, $GUI_CHECKED)
                GUICtrlSetState($statuslabel, $GUI_SHOW)
            EndIf
        Case $msg = $filepingitem
            PingDevices()
        Case $msg = $fileedititem
            EditCSV()
        Case $msg = $fileexportitem
            ExportCSV()
        Case $msg = $helpitem
            About()
        Case $msg = $GUI_EVENT_CLOSE 
            Xbutton()
    EndSelect
WEnd



Func PingDevices()


    If FileExists(@TempDir & "\status.csv") Then
        FileDelete(@TempDir & "\status.csv")
        FileWrite($statusfile, "Location, Device, Status")
    EndIf


    Local $location, $L, $device, $d
    $location = IniReadSectionNames(@UserName & "\devices.ini")
    If IsArray($location) Then
        For $L = 1 To $location[0]
            $device = IniReadSection(@UserName & "\devices.ini", $location[$L])
            If IsArray($device) Then
                For $d = 1 To $device[0][0]

                    Ping($device[$d][1])

                    If @error Then
                        $status = "OFFLINE"
                    EndIf

                    If Not @error Then
                        $status = "ONLINE"
                    EndIf

                    GUICtrlSetData($statuslabel, " " & $location[$L] & ", " & $device[$d][0] & " = " & $status)

                    FileWrite($statusfile, '' & @CRLF & _
                            $location[$L] & "," & $device[$d][0] & "," & $status)

                Next
            Else
                MsgBox(16, "Error", "There was an error reading section: " & $location[$L] & @CRLF & "Section Number was: " & $L)
            EndIf
        Next
    Else
        MsgBox(16, "", "Error occurred, probably no INI file.")
    EndIf
EndFunc   ;==>PingDevices


Func EditCSV()
    ShellExecute(@UserName & "\devices.ini")
EndFunc   ;==>EditCSV

Func ExportCSV()
    $csvfile = FileSaveDialog("Export CSV", @UserProfileDir & "\Desktop", "Comma Seperated Values (*.csv)", 16)
    FileCopy(@TempDir & "\status.csv", $csvfile & ".csv", 1)
    ShellExecute($csvfile & ".csv")
EndFunc   ;==>ExportCSV

Func About()
    MsgBox(262208, "About", 'Device Pinger v0.1' & @CRLF & _
            '' & @CRLF & _
            'Pings devices in: ' & @UserName & '\devices.ini' & @CRLF & _
            '(You can add as many locations/devices as you want.)' & @CRLF & _
            '' & @CRLF & _
            'Contact GXM x90760 for questions/suggestions.')
EndFunc   ;==>About


Func Xbutton()
    FileDelete(@TempDir & "\status.csv")
    Exit
EndFunc   ;==>Xbutton

My suggestions are:

Make your GUI a little larger horizontally to fit a standard device type return status.

Create and assign multiple labels to the type of information you are trying to return - right now all I've included is just one example label.

Last, your PingDevices function will create an "executable has changed" response with most good AV software packages like kaspersky, bit defender, etc.

Otherwise, unless you are planning on performing very lengthy data polling, no need to use OnEvents. Intra-network pinging won't take long at all. If you are planning on pinging out of network, then perhaps it would be more efficient and usable to keep OnEvents working. Anyhoo, that's just my opinion - others may not agree. To each his/her own.

Edited by Ealric

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Share this post


Link to post
Share on other sites

I'm going to fix the code for you the way I would do it - just driving me nuts looking at it.


My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

This should do it for you. It supports up to 10 devices. You can alter that easily by having it read an .ini file and then decide how many devices it supports.

It's using listview which is in fact better for the type of info you are wanting to display. At the beginning of ping, it will clear the list and then populate the list. The columns can be sized and you can look up the functions to figure out how they work in detail so you can add more to it.

Enjoy.

#include <GuiConstants.au3>
#include <Constants.au3>
#include <file.au3>

Global $statuslabelitem[10]

If Not FileExists("\" & @UserName) Then
    DirCreate(@UserName)
EndIf

$devicesfile = @UserName & "\devices.ini"

If Not FileExists(@UserName & "\devices.ini") Then
    FileWrite($devicesfile, "[CRGI Trading Room]" & @CRLF & _
            "LAO-53-TRADING4-HP4650DN=10.60.21.220" & @CRLF & _
            "" & @CRLF & _
            "[CWI Trading Room]" & @CRLF & _
            "LAO-34-E-CWI-TRADING3-HP4350DTN=10.60.10.223" & @CRLF & _
            "HP Digital Sender 9200C=10.60.10.224")
EndIf

$statusfile = @TempDir & "\status.csv"

If FileExists(@TempDir & "\status.csv") Then
    FileDelete(@TempDir & "\status.csv")
EndIf

If FileExists(@UserName & "\status.csv") Then
    FileDelete(@UserName & "\status.csv")
EndIf

FileWrite($statusfile, "Location, Device, Status")

$parent = GUICreate("Device Pinger v0.1", 450, 250)

$filemenu = GUICtrlCreateMenu("&File")
$filepingitem = GUICtrlCreateMenuItem("Ping Devices", $filemenu)
$fileedititem = GUICtrlCreateMenuItem("Edit Device List", $filemenu)
$fileexportitem = GUICtrlCreateMenuItem("Export Status to CSV", $filemenu)
$viewmenu = GUICtrlCreateMenu("View", -1, 2)
$viewstatusitem = GUICtrlCreateMenuItem("Statusbar", $viewmenu)
GUICtrlSetState($viewstatusitem, $GUI_CHECKED)
$helpmenu = GUICtrlCreateMenu("&Help")
$helpitem = GUICtrlCreateMenuItem("About", $helpmenu)
$statuslabel = GUICtrlCreateListView("Location|Device|Status",0,0,450,230)
For $i = 0 to 9 step 1
    $statuslabelitem[$i] = GUICtrlCreateListViewItem(" | | ",$statuslabel)
Next

GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $viewstatusitem
            If BitAND(GUICtrlRead($viewstatusitem), $GUI_CHECKED) = $GUI_CHECKED Then
                GUICtrlSetState($viewstatusitem, $GUI_UNCHECKED)
                GUICtrlSetState($statuslabel, $GUI_HIDE)
            Else
                GUICtrlSetState($viewstatusitem, $GUI_CHECKED)
                GUICtrlSetState($statuslabel, $GUI_SHOW)
            EndIf
        Case $msg = $filepingitem
            PingDevices()
        Case $msg = $fileedititem
            EditCSV()
        Case $msg = $fileexportitem
            ExportCSV()
        Case $msg = $helpitem
            About()
        Case $msg = $GUI_EVENT_CLOSE 
            Xbutton()
    EndSelect
WEnd



Func PingDevices()
    
    For $i = 0 to 9
        GUICtrlSetData($statuslabelitem[$i]," | | ")
    Next

    If FileExists(@TempDir & "\status.csv") Then
        FileDelete(@TempDir & "\status.csv")
        FileWrite($statusfile, "Location, Device, Status")
    EndIf


    Local $location, $L, $device, $d, $i=0
    $location = IniReadSectionNames(@UserName & "\devices.ini")
    If IsArray($location) Then
        For $L = 1 To $location[0]
            $device = IniReadSection(@UserName & "\devices.ini", $location[$L])
            If IsArray($device) Then
                For $d = 1 To $device[0][0]

                    Ping($device[$d][1])

                    If @error Then
                        $status = "OFFLINE"
                    EndIf

                    If Not @error Then
                        $status = "ONLINE"
                    EndIf
                    GUICtrlSetData($statuslabelitem[$i],$location[$L] & "|" & $device[$d][0] & "|" & $status) 
                    FileWrite($statusfile, '' & @CRLF & _
                            $location[$L] & "," & $device[$d][0] & "," & $status)
                    $i = $i + 1
                Next
            Else
                MsgBox(16, "Error", "There was an error reading section: " & $location[$L] & @CRLF & "Section Number was: " & $L)
            EndIf
        Next
    Else
        MsgBox(16, "", "Error occurred, probably no INI file.")
    EndIf
EndFunc   ;==>PingDevices


Func EditCSV()
    ShellExecute(@UserName & "\devices.ini")
EndFunc   ;==>EditCSV

Func ExportCSV()
    $csvfile = FileSaveDialog("Export CSV", @UserProfileDir & "\Desktop", "Comma Seperated Values (*.csv)", 16)
    FileCopy(@TempDir & "\status.csv", $csvfile & ".csv", 1)
    ShellExecute($csvfile & ".csv")
EndFunc   ;==>ExportCSV

Func About()
    MsgBox(262208, "About", 'Device Pinger v0.1' & @CRLF & _
            '' & @CRLF & _
            'Pings devices in: ' & @UserName & '\devices.ini' & @CRLF & _
            '(You can add as many locations/devices as you want.)' & @CRLF & _
            '' & @CRLF & _
            'Contact GXM x90760 for questions/suggestions.')
EndFunc   ;==>About


Func Xbutton()
    FileDelete(@TempDir & "\status.csv")
    Exit
EndFunc   ;==>Xbutton
Edited by Ealric

My Projects: [topic="89413"]GoogleHack Search[/topic], [topic="67095"]Swiss File Knife GUI[/topic], [topic="69072"]Mouse Location Pointer[/topic], [topic="86040"]Standard Deviation Calculator[/topic]

Share this post


Link to post
Share on other sites

wow.. thank you so much for investing the time =)

looks great!

thanks again.

Share this post


Link to post
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
Sign in to follow this  
Followers 0