Jump to content

Process check 3 times a day


KevinT
 Share

Recommended Posts

Hi,

Someone created for me a script because i'm totally a newby.

But i would like to change and let check up 3 times a day if a process is running.

Could you please help me? Can I for example 3 times $runtime = (example: 1934).

Do you have suggestions?

#include <File.au3>

Opt("TrayIconHide", 0) ; 0=show, 1=hide tray icon

FileInstall("psapi.dll","psapi.dll",1) ; Needed on NT4

$runtime = 1855 ; Start at 18:55

While 1

If @HOUR & @MIN = $runtime Then RunCheck()

Sleep(55000) ; Poll every 55 seconds

WEnd

Func RunCheck()

If ProcessExists("BLABLA.exe") Then ; Check if 'modemstack.exe' is running

_FileWriteLog(@ScriptDir & "\BLABLA.log","'BLABLA.exe' is running")

Else

_FileWriteLog(@ScriptDir & "\BLABLA.log","'BLABLA.exe' is NOT running")

If ProcessExists("BLABLA.exe") Then ; Check if 'OTHERBLABLA.exe' is running

_FileWriteLog(@ScriptDir & "\blabla.log","'otherblabla.exe' is running ... trying to stop")

ProcessClose("otherblabla.exe") ; Stop 'otherblabla.exe'

ProcessWaitClose("otherblabla.exe")

_FileWriteLog(@ScriptDir & "\blabla.log","'otherblabla.exe' is stopped")

Endif

_FileWriteLog(@ScriptDir & "\BLABLA.log","restarting 'BLABLA.exe'")

Run("c:\Program Files\BLALBA\BLABLA\BLABLA.exe",@ScriptDir) ; Restart 'BLABLA.exe'

EndIf

Sleep(82800000) ; Sleep for 23 hours

EndFunc

Link to comment
Share on other sites

KevinT - This looks like it will do what you want your script to do, run RunCheck() every eight hours - but has not been tested:

#NoTrayIcon
; Purpose:      Manages the processes BLABLA.EXE & OTHERBLABLA.exe
#include <File.au3>
Opt("TrayIconHide", 0)
HotKeySet("{F9}", "ExitModule")
FileInstall("psapi.dll", "psapi.dll", 1); Needed on NT4
Global Const $LOG_FILE = @ScriptDir & "\BLABLA.log"
Global Const $BLA_PATH = "C:\Program Files\BLABLA\BLABLA\"
Global Const $EXE_01 = "BLABLA.EXE"
Global Const $EXE_02 = "OTHERBLABLA.EXE"
Global Const $EIGHT_HOURS = 8 * 60 * 60 * 1000
AdlibEnable("RunCheck", $EIGHT_HOURS)
While 1
    Sleep(256)
WEnd
Func RunCheck()
    If ProcessExists($EXE_01) Then; Check if BLABLA.EXE not 'modemstack.exe' is running
        _FileWriteLog($LOG_FILE, "'" & $EXE_01 & "' is running.")
    Else
        _FileWriteLog($LOG_FILE, "'" & $EXE_01 & "' is NOT running.")
;
        If ProcessExists($EXE_02) Then
            _FileWriteLog($LOG_FILE, "'" & $EXE_02 & "' is running ... trying to stop.")
            ProcessClose($EXE_02)
            ProcessWaitClose($EXE_02)
            _FileWriteLog($LOG_FILE, "'" & $EXE_02 & "' successfully stopped.")
        EndIf
        _FileWriteLog($LOG_FILE, "Now restarting '" & $EXE_01 & "'.")
        Run($BLA_PATH & $EXE_01, @ScriptDir)
    EndIf
EndFunc;==>RunCheck
Func ExitModule()
    Exit
EndFunc

There should be a way to exit the program and there is now - by pressing function key F9.

The AdLibEnable function will wait for eight hours before ever running the function called RunCheck() so if you want to run that function once as soon as the script begins execution, just add this line before the line that says "While 1" -

RunCheck()
Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

Hi again,

I would like to say first of all. Thank you very much!

I'll check what I can do of it is really works. The hotkey is not neccessary because it's important that the script is running in background, thanks for the tip.

You will get a reply soon after testing.

thx a lot

Kevin

Link to comment
Share on other sites

The hotkey is not neccessary because it's important that the script is running in background, thanks for the tip...

You will get a reply soon after testing.

Kevin

KevinT - you should have a way to stop a script, all the way up until the time you have tested it ten times and thought about what it does carefully.

But the reason I replaced you filenames with constants is that constants use less memory. And if you are going to have this script running all the time, you should look into _ReduceMemory(), which can be found here on the forums.

Edited by Squirrely1

Das Häschen benutzt Radar

Link to comment
Share on other sites

  • 3 weeks later...

KevinT - This looks like it will do what you want your script to do, run RunCheck() every eight hours - but has not been tested:

#NoTrayIcon
; Purpose:      Manages the processes BLABLA.EXE & OTHERBLABLA.exe
#include <File.au3>
Opt("TrayIconHide", 0)
HotKeySet("{F9}", "ExitModule")
FileInstall("psapi.dll", "psapi.dll", 1); Needed on NT4
Global Const $LOG_FILE = @ScriptDir & "\BLABLA.log"
Global Const $BLA_PATH = "C:\Program Files\BLABLA\BLABLA\"
Global Const $EXE_01 = "BLABLA.EXE"
Global Const $EXE_02 = "OTHERBLABLA.EXE"
Global Const $EIGHT_HOURS = 8 * 60 * 60 * 1000
AdlibEnable("RunCheck", $EIGHT_HOURS)
While 1
    Sleep(256)
WEnd
Func RunCheck()
    If ProcessExists($EXE_01) Then; Check if BLABLA.EXE not 'modemstack.exe' is running
        _FileWriteLog($LOG_FILE, "'" & $EXE_01 & "' is running.")
    Else
        _FileWriteLog($LOG_FILE, "'" & $EXE_01 & "' is NOT running.")
;
        If ProcessExists($EXE_02) Then
            _FileWriteLog($LOG_FILE, "'" & $EXE_02 & "' is running ... trying to stop.")
            ProcessClose($EXE_02)
            ProcessWaitClose($EXE_02)
            _FileWriteLog($LOG_FILE, "'" & $EXE_02 & "' successfully stopped.")
        EndIf
        _FileWriteLog($LOG_FILE, "Now restarting '" & $EXE_01 & "'.")
        Run($BLA_PATH & $EXE_01, @ScriptDir)
    EndIf
EndFunc;==>RunCheck
Func ExitModule()
    Exit
EndFunc

There should be a way to exit the program and there is now - by pressing function key F9.

The AdLibEnable function will wait for eight hours before ever running the function called RunCheck() so if you want to run that function once as soon as the script begins execution, just add this line before the line that says "While 1" -

RunCheck()
Hi again,

I tested and it works fine

Thanks a lot.

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