Jump to content

how to get the PID of an application after each time it changed


camilla
 Share

Recommended Posts

camilla,

The following reads event records for event service start (corresponds closely to Windows startup).

Two variables allow you to designate how many times the pc is allowed to be restarted ($Num_Restarts_Allowed) in what time frame ($Monitoring_Period).

Tested on Win7 (64bit) under Autoit 3.3.10+

#include <EventLog.au3>
#include <array.au3>
#include <MsgBoxConstants.au3>

OnAutoItExitRegister('_fini')

Local $hEventLog, $aEvent, $cnt = 0, $dte

local $Num_Restarts_Allowed = 1     ; # of restarts allowed for monitoring period
local $Monitoring_Period    = 24    ; time period for # of restarts in hours

$hEventLog = _EventLog__Open("", "System")
if $hEventLog = 0 then
    ConsoleWrite('Log failed to open' & @LF)
    Exit
endif

while 1

    $aEvent = _EventLog__Read($hEventLog, True, False)
    if $aEvent[0] = false then exit
    if $aEvent[6] = 6005  then
        $dte = stringright($aEvent[4],4) & '/' & StringLeft($aEvent[4],2) & '/' & stringmid($aEvent[4],4,2) & ' ' & stringleft($aEvent[5],8)
        $cnt += 1
        if _datediff('h',$dte,_nowcalc()) > $Monitoring_Period  then
            exit
        endif
        if $cnt > $Num_Restarts_Allowed then
            if _datediff('h',$dte,_nowcalc()) < $Monitoring_Period then
                if msgbox($MB_OKCANCEL,'Restart Limit Exceeded','Reply:' & @crlf & '    [OK]    to continue' & @crlf & '    [Cancel]    to abort restart') = $idOK then
                    exit
                Else
                    ;
                    ; do denial routine here, perhaps shutdown
                    ;
                EndIf
            endif
        EndIf
    endif

wend

func _fini()
    _EventLog__Close($hEventLog)
endfunc

This is only a skeleton of how this might be done and probably needs more error checking and testing.

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

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