Process Uptime

  • Hey..

    Hab keine Funktion dafür gefunden und auch hier im Forum nichts dazu gefunden.
    Deshalb hier mal mein Problem.

    Spoiler anzeigen
    [autoit]

    #include <date.au3>
    Opt("OnExitFunc", "endscript")
    Global $uptimeAllseconds, $uptimeAllMinutes, $uptimeAllHours

    [/autoit] [autoit][/autoit] [autoit]

    no_process()
    Func no_process()
    Do
    Sleep (100)
    Until ProcessExists ($process)
    process()
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func process()
    IniWrite (@ScriptDir & "\process_Uptime.ini", "time", "start", _NowCalc())
    While 1
    $uptimeNowSeconds = _DateDiff ("s", IniRead (@ScriptDir & "\process_Uptime.ini", "time", "start", ""), _NowCalc())
    $uptimeNowMinutes = Round(IniRead (@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") / 60, 2)
    $uptimeNowHours = Round (IniRead (@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") /3600, 2)

    $uptimeAllseconds = IniRead (@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") + IniRead (@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", "")
    $uptimeAllMinutes = Round((IniRead (@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") + IniRead (@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", "")) / 60, 2)
    $uptimeAllHours = Round ((IniRead (@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") + IniRead (@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", "")) /3600, 2)


    IniWrite (@ScriptDir & "\process_Uptime.ini", "time", "uptimeNowSeconds", $uptimeNowSeconds)
    IniWrite (@ScriptDir & "\process_Uptime.ini", "time", "uptimeNowMinutes", $uptimeNowMinutes)
    IniWrite (@ScriptDir & "\process_Uptime.ini", "time", "uptimeNowHours", $uptimeNowHours)

    TrayTip ("process Uptime", "Now: " & $uptimeNowSeconds & "seconds | "& $uptimeNowMinutes & "minutes | " &$uptimeNowHours & "hours" & @LF & "All: " & $uptimeAllseconds & "seconds | " & $uptimeAllMinutes & "minutes | " &$uptimeAllHours & "hours", 1)
    If Not ProcessExists ($process) Then
    IniWrite (@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", $uptimeAllseconds)
    IniWrite (@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllMinutes", $uptimeAllMinutes)
    IniWrite (@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllHours", $uptimeAllHours)

    no_process()
    EndIF
    WEnd
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    Func endscript()
    IniWrite (@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", $uptimeAllseconds)
    IniWrite (@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllMinutes", $uptimeAllMinutes)
    IniWrite (@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllHours", $uptimeAllHours)
    EndFunc

    [/autoit]

    Allso das funktioniert alles so weit. Nun wollte ich das Script umschreiben, so dass es im background läuft.
    Meine Idee dazu war, ein TrayMenu zu erstellen, wenn man dann auf Uptime -> Show klickt, soll ein GUI kommen, dass man dann wieder schliessen kann.
    Nachdem man das GUI geschlossen hat, soll mit dem Loop vom TrayMenu weiter gemacht werden.
    Habs mit verschiedenen Funktionen versucht, dass hat alles so weit geklappt.
    Also GUI öffnen -> Schliessen -> zurück zur TrayMenu funktion.
    Alles Wunderbar.
    Nur nachdem ich das gemacht habe und wieder das GUI öffne, stimmt die Zeit überhaupt nicht mehr. :/
    Hier mal was ich habe.

    Spoiler anzeigen
    [autoit]

    #include <GUIConstants.au3>
    #include <Constants.au3>
    #include <date.au3>
    #NoTrayIcon

    [/autoit] [autoit][/autoit] [autoit]

    Opt("TrayMenuMode", 1) ; Standard Traymenüeinträge (Script pausieren/beenden) werden nicht angezeigt.
    Global $uptimeAllseconds, $uptimeAllMinutes, $uptimeAllHours
    Global $settingsitem = TrayCreateMenu("Uptime")
    Global $show = TrayCreateItem("Show", $settingsitem)
    TrayCreateItem("")
    Global $aboutitem = TrayCreateItem("About")
    TrayCreateItem("")
    Global $exititem = TrayCreateItem("Beenden")
    TraySetState()
    start()
    Func start()
    Select
    Case Not ProcessExists($process)
    MsgBox(64, "Error!", $process & "not found!")
    noprocess()
    Case Else
    Tray()
    EndSelect
    EndFunc ;==>start

    [/autoit] [autoit][/autoit] [autoit]

    Func Tray()
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "start", _NowCalc())
    While 1
    $array = __DaysInMonth(@YEAR)

    $uptimeNowSeconds = _DateDiff("s", IniRead(@ScriptDir & "\process_Uptime.ini", "time", "start", ""), _NowCalc())
    $uptimeNowMinutes = Round(IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") / 60, 2)
    $uptimeNowHours = Round(IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") / 3600, 2)

    $uptimeNowDays = Round(IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") / (3600 * 24), 2)
    $uptimeNowWeeks = Round(IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") / (3600 * 24 * 7), 2)

    $uptimeAllseconds = IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") + IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", "")
    $uptimeAllMinutes = Round((IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") + IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", "")) / 60, 1)
    $uptimeAllHours = Round((IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") + IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", "")) / 3600, 2)
    $uptimeAllDAys = Round((IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") + IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", "")) / (3600 * 24), 2)
    $uptimeAllWeeks = Round((IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") + IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", "")) / (3600 * 24 * 7), 2)
    $uptimeAllMonths = Round((IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") + IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", "")) / (3600 * 24 * $array[@MON]), 2)

    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNowSeconds", $uptimeNowSeconds)
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNowMinutes", $uptimeNowMinutes)
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNowHours", $uptimeNowHours)

    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", $uptimeAllseconds)
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllMinutes", $uptimeAllMinutes)
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllHours", $uptimeAllHours)
    #Region ### changeALL ###
    ;~ GUICtrlSetData($changeAllSec, $uptimeAllseconds)
    ;~ GUICtrlSetData($changeAllMin, $uptimeAllMinutes)
    ;~ GUICtrlSetData($changeAllHours, $uptimeAllHours)
    ;~ GUICtrlSetData($changeAllDays, $uptimeAllDAys)
    ;~ GUICtrlSetData($changeAllWeeks, $uptimeAllWeeks)
    ;~ GUICtrlSetData($changeAllMonths, $uptimeAllMonths)
    ;~ #EndRegion ### changeALL ###
    ;~ #Region ### changeNOW ###
    ;~ GUICtrlSetData($changeNowSec, $uptimeNowSeconds)
    ;~ GUICtrlSetData($changeNowMin, $uptimeNowMinutes)
    ;~ GUICtrlSetData($changeNowHours, $uptimeNowHours)
    ;~ GUICtrlSetData($changeNowDays, $uptimeNowDays)
    ;~ GUICtrlSetData($changeNowWeeks, $uptimeNowWeeks)
    ;~ #EndRegion ### changeNOW ###
    $msg = TrayGetMsg()
    Select
    Case $msg = 0
    ContinueLoop
    Case $msg = $aboutitem
    ContinueLoop
    Case $msg = $show
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNowSeconds", $uptimeNowSeconds)
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNowMinutes", $uptimeNowMinutes)
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNowHours", $uptimeNowHours)

    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", $uptimeAllseconds)
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllMinutes", $uptimeAllMinutes)
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllHours", $uptimeAllHours)
    Gui()
    Case $msg = $exititem
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", $uptimeAllseconds)
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllMinutes", $uptimeAllMinutes)
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllHours", $uptimeAllHours)
    Exit
    EndSelect
    WEnd
    EndFunc ;==>Tray

    [/autoit] [autoit][/autoit] [autoit]

    Func noprocess()
    While 1
    $msg = TrayGetMsg()
    Select
    Case $msg = 0
    ContinueLoop
    Case $msg = $aboutitem
    ContinueLoop
    Case $msg = $show
    #Region --- CodeWizard generated code Start ---
    ;MsgBox features: Title=Yes, Text=Yes, Buttons=Retry and Cancel, Icon=Warning
    If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
    $iMsgBoxAnswer = MsgBox(53, "Error!", "No process_client.exe found!" & @CRLF & "Press Retry for a new try!")
    Select
    Case $iMsgBoxAnswer = 4 ;Retry
    start()
    Case $iMsgBoxAnswer = 2 ;Cancel
    ContinueLoop
    EndSelect
    #EndRegion --- CodeWizard generated code Start ---
    Case $msg = $exititem
    Exit
    EndSelect
    WEnd
    EndFunc ;==>noprocess

    [/autoit] [autoit][/autoit] [autoit]

    Func Gui()
    $Form1 = GUICreate("process Uptime", 386, 180, 193, 125)
    $Group1 = GUICtrlCreateGroup("Uptime Now", 0, 0, 185, 145)
    $Label1 = GUICtrlCreateLabel("Seconds", 8, 24, 46, 17)
    $Label2 = GUICtrlCreateLabel("Minutes", 8, 48, 41, 17)
    $Label3 = GUICtrlCreateLabel("Hours", 8, 72, 32, 17)
    $Label4 = GUICtrlCreateLabel("Days", 8, 96, 28, 17)
    $Label5 = GUICtrlCreateLabel("Weeks", 8, 120, 38, 17)
    $changeNowSec = GUICtrlCreateLabel("changeNowSec", 80, 24, 81, 17)
    $changeNowMin = GUICtrlCreateLabel("Label12", 80, 48, 42, 17)
    $changeNowDays = GUICtrlCreateLabel("Label12", 80, 96, 42, 17)
    $changeNowHours = GUICtrlCreateLabel("Label12", 80, 72, 42, 17)
    $changeNowWeeks = GUICtrlCreateLabel("Label12", 80, 120, 42, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Group2 = GUICtrlCreateGroup("Uptime All", 192, 0, 185, 169)
    $Label6 = GUICtrlCreateLabel("Seconds", 200, 24, 46, 17)
    $Label7 = GUICtrlCreateLabel("Weeks", 200, 120, 38, 17)
    $Label8 = GUICtrlCreateLabel("Days", 200, 96, 28, 17)
    $Label9 = GUICtrlCreateLabel("Hours", 200, 72, 32, 17)
    $Label10 = GUICtrlCreateLabel("Minutes", 200, 48, 41, 17)
    $Label11 = GUICtrlCreateLabel("Months", 200, 144, 39, 17)
    $changeAllSec = GUICtrlCreateLabel("Label12", 272, 24, 42, 17)
    $changeAllWeeks = GUICtrlCreateLabel("Label12", 272, 120, 42, 17)
    $changeAllDays = GUICtrlCreateLabel("Label12", 272, 96, 42, 17)
    $changeAllHours = GUICtrlCreateLabel("Label12", 272, 72, 42, 17)
    $changeAllMin = GUICtrlCreateLabel("Label12", 272, 48, 42, 17)
    $changeAllMonths = GUICtrlCreateLabel("Label12", 272, 144, 42, 17)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    $Exitbtn = GUICtrlCreateButton("Exit", 0, 152, 187, 20, 0)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $array = __DaysInMonth(@YEAR)

    $uptimeNowSeconds = _DateDiff("s", IniRead(@ScriptDir & "\process_Uptime.ini", "time", "start", ""), _NowCalc())
    $uptimeNowMinutes = Round(IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") / 60, 2)
    $uptimeNowHours = Round(IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") / 3600, 2)

    $uptimeNowDays = Round(IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") / (3600 * 24), 2)
    $uptimeNowWeeks = Round(IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") / (3600 * 24 * 7), 2)

    $uptimeAllseconds = IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") + IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", "")
    $uptimeAllMinutes = Round((IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") + IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", "")) / 60, 1)
    $uptimeAllHours = Round((IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") + IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", "")) / 3600, 2)
    $uptimeAllDAys = Round((IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") + IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", "")) / (3600 * 24), 2)
    $uptimeAllWeeks = Round((IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") + IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", "")) / (3600 * 24 * 7), 2)
    $uptimeAllMonths = Round((IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNOWSeconds", "") + IniRead(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", "")) / (3600 * 24 * $array[@MON]), 2)

    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNowSeconds", $uptimeNowSeconds)
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNowMinutes", $uptimeNowMinutes)
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNowHours", $uptimeNowHours)
    #Region ### changeALL ###
    GUICtrlSetData($changeAllSec, $uptimeAllseconds)
    GUICtrlSetData($changeAllMin, $uptimeAllMinutes)
    GUICtrlSetData($changeAllHours, $uptimeAllHours)
    GUICtrlSetData($changeAllDays, $uptimeAllDAys)
    GUICtrlSetData($changeAllWeeks, $uptimeAllWeeks)
    GUICtrlSetData($changeAllMonths, $uptimeAllMonths)
    #EndRegion ### changeALL ###
    #Region ### changeNOW ###
    GUICtrlSetData($changeNowSec, $uptimeNowSeconds)
    GUICtrlSetData($changeNowMin, $uptimeNowMinutes)
    GUICtrlSetData($changeNowHours, $uptimeNowHours)
    GUICtrlSetData($changeNowDays, $uptimeNowDays)
    GUICtrlSetData($changeNowWeeks, $uptimeNowWeeks)
    #EndRegion ### changeNOW ###
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE, $Exitbtn
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNowSeconds", $uptimeNowSeconds)
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNowMinutes", $uptimeNowMinutes)
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeNowHours", $uptimeNowHours)

    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllSeconds", $uptimeAllseconds)
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllMinutes", $uptimeAllMinutes)
    IniWrite(@ScriptDir & "\process_Uptime.ini", "time", "uptimeAllHours", $uptimeAllHours)
    GUIDelete($Form1)
    Tray()

    [/autoit] [autoit][/autoit] [autoit]

    EndSwitch
    WEnd
    EndFunc ;==>Gui

    [/autoit]

    ist ein wenig unübersichtlich, aber wenn mir jemand dabei helfen würde, würde mich das dann doch sehr freuen. :P

    mfg ^T!Tu$

    Einmal editiert, zuletzt von ^T!Tu$ (26. Juni 2008 um 21:28)

  • Hi,
    also $process ist dicht deklariert und wenn ich das Script starte, dann kommt eine MsGbox mit "Error not Found"

    Also ich glaube da funktioniert so einiges net.
    Was für einen Prozess sucht er denn? Den der angegeben ist kenne ich net und läuft bei mir auch net.
    Vielleicht solltest du uns den Source der "process_client.exe" mal posten damit man das ganze mal testen kann.
    MfG
    Der_Doc

  • ups. :P
    hab vorher noch das script bissl verändert. damit man es auch für verschiedene Prozesse benutzen kann.
    da das script für ein spiel (Silkroad) benutzt werden soll (bei mir), hatte ich es noch verändert, da ja nich jeder SRO spielt. ;)

    also $prozcess einfach deklarieren. ;)

  • also bei mir funzt das script auch, wenn keine INI im selben ordner ist.

    der prozess wird bei mir direkt als sro_client.exe ausgewählt. also bei mir im script gibts keine $process.. aber das hat ja nichts mit der sache zu tun. ;)

  • Global $process = "explorer.exe"
    vor das script.. dann läufts wenigstens mal. ;)

    //Edit:

    so funzt. war n fehler bei den ganzen IniWrites und IniReads ;)

    Einmal editiert, zuletzt von ^T!Tu$ (26. Juni 2008 um 21:27)