Jump to content

Process checker/restarter


Bella
 Share

Recommended Posts

Greetings everyone. i must say i love this program i only have about 2 days experence and ive coded most of it myself

anyways im working on an autorestarter.. yeah i know this sounds lame and easy but it isnt

you see when this exe "Mangosd.exe" crashes. it doesnt close. it sits there. so what i figured i do is scan the Server.log for a string like " Haulting process"

if that exists then delete the server.log and restart the exe... simple right?

/cry heres my code.

; search.au3
; usage search.exe filename searchword
#include <Sound.au3>
#include <GUIConstants.au3>
Global Const $ProcessCheck = ProcessExists("realmd.exe")
Global Const $ProcessEnd = ProcessClose("realmd.exe")
Global Const $Crash = RunWait('find "Halting process..." "Server.log","",@SW_HIDE')
Global Const $Delete = FileDelete("mangos.log")
Global Const $aim = ProcessExists("Aim.exe")
Global Const $Serverlog = FileOpen("server.log", 0)
;=======================================================================
;  Checking if mangos is running  , if = 1,  Kill Mangosd.exe          |
;=======================================================================
#include <GUIConstants.au3>

GUICreate("Mangos Mastermind v2.0.01")

Opt("GUICoordMode",2)
$Button_1 = GUICtrlCreateButton ("Run World server",  10, 30, 100)
$Button_2 = GUICtrlCreateButton ( "Run Realm server",  0, -1)
$Button_3 = GUICtrlCreateButton ( "Clear Server.log",  0, -1)
$Button_4 = GUICtrlCreateButton ( "Crash Handler",  0, -1)

GUISetState ()      ; will display an  dialog box with 2 button

; Run the GUI until the dialog is closed
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $Button_1
            Run("Mangosd.exe")
        Case $msg = $Button_2
            Run("realmd.exe")
        Case $msg = $Button_3
            FileDelete("Server.log")
            MsgBox(0, 'Mangos Mastermind', '"Server.log" Secussfully Cleaned!')
        Case $msg = $Button_4
             Logcheck($Serverlog)
    EndSelect
Wend
 

;=======================================================================
;  Crash Detector                                                      |
;=======================================================================


;=======================================================================
;       Functions
;=======================================================================

Func Crashcheck($Crash)
    Select
        Case $Crash = 1
            Msgbox(4096,"",'Yep.. its there.')
        Case $Crash = 0
            Msgbox(4096,"",'nope were aids free.')
    EndSelect
EndFunc


Func ReadLog($processCheck)
    Select
        Case $ProcessCheck = 0 
            MsgBox(4096,"",'Realm server not detected.')
        Case $ProcessCheck = 1
            MsgBox(4096,"",'Realm server already online.')
        EndSelect

EndFunc

Func Logcheck($Serverlog)
    Select
        Case $Serverlog = 0
            MsgBox(4096,"",'Server.log Is missing.')
        Case $Serverlog = 1
            MsgBox(4096,"",'Server.Log is HERE!.')
    EndSelect
EndFunc

its really messy i know, but please have some paitentce i might be of use to the forms later some day

and also if i may ask, please dont bash me if im doing something way to hard or stupid, it would be nice

just to know that you have a better, more efficient way

<3

--bella

Edited by Bella
Link to comment
Share on other sites

First of all, I'd like to congratulate you on making some sort of effort before posting a question. After going through your script, I realized I could spend a lot of time discussing how to fix up your script. I will tell you the obvious mistakes you made.

Firstly, If you want to check for something every X seconds, you cannot state it as a Global Const. Instead, you must put it inside your While..WEnd loop. So, to cut to the chase, delete all your Global Const's. It should look something like this.. I wrote this up for you, however it took me half a minute so don't think I'm that generous.

$timer = TimerInit()
While 1
    If TimerDiff($timer) > 10000 Then ;Every 10 seconds, we do the following:
        $FileRead = FileRead("server.log") ;$FileRead contains the characters in the file
        If StringInStr($FileRead, "Halting process...") Then
            MsgBox(0,"","PROCESS IS HALTED!!")
        Else
            MsgBox(0,"","PROCESS IS NOT HALTED")
        EndIf
        $timer = 0
        $timer = TimerInit()
    EndIfoÝ÷ Ù¦zfÞ®ØZ¶Ø^±Êâ¦Ù®²ÖÞ{azÇ«½êå¢b­ç-¢¼Ø^®ØZ¶ò¢é®²×!jx¶W©jØ@Ê$yêbh§vØZ¶Øb²+(­ëh¦«¶ò¢êÖ)^XIÝ)2â
'"ÇÊ·ö÷®±çmçèZ0x-Â'|¨º»®*mjëh×6#Include <GUIConstants.au3>

This should be only used once (preferrably at the start of your script with your other #Include's). For more information on declaring variable's, look in the helpfile (press F1 in SciTe for quick-access). Well there are most of your problems, glad to get that off my chest. Post any more problems you experience and we* will be glad to help.

Good Luck,

Kurt

*please note that not all members of this forum will gladly give you suggestions & example scripts.. So use the helpfile :whistle:

EDIT: Forgot to declare $timer variable

Edited by _Kurt

Awaiting Diablo III..

Link to comment
Share on other sites

Well since you have given to me I shall give back to the communitity

$timer = TimerInit()
While 1
    If TimerDiff($timer) > 10000 Then;Every 10 seconds, we do the following:
        $FileRead = FileRead("server.log");$FileRead contains the characters in the file
        If StringInStr($FileRead, "Halting process...") Then
        $destination = "downarrow2.gif"
            SplashImageOn("Online", $destination, 32, 34, "", "", 1)
            ProcessClose("mangosd.exe")
            Run("mangosd.exe")
        Else
        $destination = "uparrow2.gif"
            SplashImageOn("Online", $destination, 32, 34, "", "", 1)
        EndIf
        $timer = 0
        $timer = TimerInit()
    EndIf
WEnd

now Basically what this program does is checks the current Directory for an exe called Mangosd.exe which is an emulator for a private world of warcraft server. it also reads the output it logs to server.log, and then checks if there was an error with mangos. if the error exist it will close mangos then, reopen it.

Mangos clears the server log each restart so no need for a delete funct.

anyways just throw two images in there. one for an online status, than one for a offline

Again this code can be modified to work for anything. Anyways thanks so much again. i really apprechate it

and i hope i dont piss you off by saying i love you again. i am extremly greatfull :whistle:

Link to comment
Share on other sites

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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