Jump to content

Recommended Posts

Posted

Hi @ all,

i have a little question. I created a GUI to monitor a Service. The GUI Displays the Status of the Service and the Server. It should ping the server all 60 seconds and look if a process still exists all 120 seconds. But you sould also can click on the GUI Buttons. Where should i put the code for checking this stuff? Because if i put it "Case Else" the GUI is blocked for 60 seconds...

Thanks for helping me.

Regards,

CoDeX2k

Posted

  BabyBeast said:

not sure of yourcode but 60sec or not you can use guisetdata to make changes on your gui while in the time loop and checking for your service

Yeah, i allready use GUISETData. But i can't checking it while using the GUI :-( If i check i can't use the GUI. If i use the GUI i can't check...

regards,

Posted

I can't get it work display the status and buttons and check in the background the availibility of an ip with ping... and processexist("service.exe") for the service.

If i do it like this

Case Else
    Sleep(60000)
    _CheckService()
EndSelect

I can't close or control the form in this 60 seconds...

Anybody an idea?

Thanks

Regards,

CoDeX2k

Posted

Don't use such a big sleep.

Look at the Timer functions and only act when your desired interval is reached.

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Posted

Okay, i post the hole code of the Script

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.1.1.130 BETA
; Author:        CoDeX2k <codex2k@gmx.net>
;
;
;Service Monitor
;
; ----------------------------------------------------------------------------

#include <GUIConstants.au3>

$frmStatus = GUICreate("Service Monitor", 183, 98, 413, 232,-1,-1)
GUICtrlCreateLabel("Service Status:", 8, 8, 66, 17)
    If ProcessExists("service.exe")=0 Then
        $servicestatus=GUICtrlCreateLabel("Stopped", 80, 8, 84, 20)
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor(-1, 0xFF0000)
    Else
        $servicestatus=GUICtrlCreateLabel("Running", 80, 8, 84, 20)
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor(-1, 0x008000)
    EndIf
    $btnShutdown = GUICtrlCreateButton("Shutdown", 8, 64, 75, 25)
    $btnRestart = GUICtrlCreateButton("Restart", 96, 64, 75, 25)
    Opt("TrayIconHide", 1)
    GUICtrlCreateLabel("Internet Status:", 8, 32, 71, 17)
    If Ping("www.google.de")>0 Then
        $internetstatus=GUICtrlCreateLabel("Up", 80, 32, 100, 20)
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor(-1, 0x008000)
    Else
        $internetstatus=GUICtrlCreateLabel("Down", 80, 32, 100, 20)
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor(-1, 0xFF0000)
    EndIf
    GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit
    Case $msg = $btnShutdown
    ;Shutdown
    Case $msg = $btnRestart
    ;Restart
    Case Else
        _CheckInternetConnection()
        _CheckServiceStatus()
    EndSelect
WEnd

Func _CheckInternetConnection()
    Sleep(60000)
    If Ping("www.google.de")>0 Then
        GUICtrlSetData($internetstatus,"Up")
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor(-1, 0x008000)
    Else
        GUICtrlSetData($internetstatus,"Down")
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor(-1, 0xFF0000)
    EndIf
EndFunc
    
Func _CheckServiceStatus()
    Sleep(120000)
    If ProcessExists("service.exe")=0 Then
        GUICtrlsetdata($servicestatus,"Stopped")
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor(-1, 0xFF0000)
    Else
        GUICtrlSetData($servicestatus,"Running")
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor(-1, 0x008000)
    EndIf
EndFunc

Regards,

CoDeX2k

  • Moderators
Posted

Global $iKeepCount
#include <GUIConstants.au3>
AdlibEnable('_AdlibManager', 60000)

$frmStatus = GUICreate("Service Monitor", 183, 98, 413, 232,-1,-1)
GUICtrlCreateLabel("Service Status:", 8, 8, 66, 17)
    If ProcessExists("service.exe")=0 Then
        $servicestatus=GUICtrlCreateLabel("Stopped", 80, 8, 84, 20)
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor(-1, 0xFF0000)
    Else
        $servicestatus=GUICtrlCreateLabel("Running", 80, 8, 84, 20)
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor(-1, 0x008000)
    EndIf
    $btnShutdown = GUICtrlCreateButton("Shutdown", 8, 64, 75, 25)
    $btnRestart = GUICtrlCreateButton("Restart", 96, 64, 75, 25)
    Opt("TrayIconHide", 1)
    GUICtrlCreateLabel("Internet Status:", 8, 32, 71, 17)
    If Ping("www.google.de")>0 Then
        $internetstatus=GUICtrlCreateLabel("Up", 80, 32, 100, 20)
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor(-1, 0x008000)
    Else
        $internetstatus=GUICtrlCreateLabel("Down", 80, 32, 100, 20)
        GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor(-1, 0xFF0000)
    EndIf
    GUISetState(@SW_SHOW)

While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit
    Case $msg = $btnShutdown
    ;Shutdown
    Case $msg = $btnRestart
    ;Restart
    Case Else
        _CheckInternetConnection()
        _CheckServiceStatus()
    EndSelect
WEnd

Func _AdlibManager()
    $iKeepCount = $iKeepCount + 1
    _CheckInternetConnection()
    If $iKeepCount = 2 Then
        _CheckServiceStatus()
        $iKeepCount = 0
    EndIf
EndFunc

Func _CheckInternetConnection()
    If Ping("www.google.de") Then
        GUICtrlSetData($internetstatus,"Up")
        GUICtrlSetFont($internetstatus, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor($internetstatus, 0x008000)
    Else
        GUICtrlSetData($internetstatus,"Down")
        GUICtrlSetFont($internetstatus, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor($internetstatus, 0xFF0000)
    EndIf
EndFunc
    
Func _CheckServiceStatus()
    If Not ProcessExists("service.exe") Then
        GUICtrlsetdata($servicestatus,"Stopped")
        GUICtrlSetFont($servicestatus, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor($servicestatus, 0xFF0000)
    Else
        GUICtrlSetData($servicestatus,"Running")
        GUICtrlSetFont($servicestatus, 8, 800, 0, "MS Sans Serif")
        GUICtrlSetColor($servicestatus, 0x008000)
    EndIf
EndFunc

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.

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...