Jump to content

Watchdog


myspacee
 Share

Recommended Posts

Watchdog program,

sure exist but make my own. muttley

first run, make list of your 'safe' program (.exe)

second run, monitor running .exe and kill if not in list

Shift + Alt + d to exit

: edited :

Use sysinternal pskill to kill process, copy pskill.exe to you c:\ if compile.

download it from microsoft

;////////////////////////////////////////////////////////////////////
;//   Watchdog  - kill not allowed programs
;////////////////////////////////////////////////////////////////////
#NoTrayIcon
HotKeySet("+!d", "Terminate");Shift-Alt-d
;////////////////////////////////////////////////////////////////////
;//   ONLY ONE SESSION AT TIME
;////////////////////////////////////////////////////////////////////
$list = ProcessList(@ScriptName)
for $i = 1 to $list[0][0]
    if $i > 1 Then
        msgbox(0, "Alert!", "Only one instance is allowed : " & @ScriptName, 1)
        ProcessClose($list[$i][1])
    EndIf
next
;//////////////////////////////////////////////////////////////////////
;//   copy Sysinternal pskill in working directory
;//////////////////////////////////////////////////////////////////////
If FileExists(@WorkingDir & "\pskill.exe") Then
;do nothing
Else
    FileInstall("c:\pskill.exe", @WorkingDir & "\pskill.exe", 1)
EndIf
    

;//////////////////////////////////////////////////////////////////////
;//   MAIN
;//////////////////////////////////////////////////////////////////////

if FileExists("allowed.ini") then ;if .ini exists kill other process
    While 1
        XenoKiller()
        sleep(1000)
    WEnd
else
    StoreRunning()              ;if .ini NOT exists create file/list 
EndIf




;//////////////////////////////////////////////////////////////////////
;//   FUNCTIONS
;//////////////////////////////////////////////////////////////////////
;//   FIRST RUN create allowed .exe list
;//////////////////////////////////////////////////////////////////////
Func StoreRunning($file = "allowed.ini")
; List all processes in a File
    local $list = ProcessList()
    
    for $i = 1 to $list[0][0]
        FileWriteLine("allowed.ini", $list[$i][0] & @CRLF)
    next
    msgbox(0, "First Run", "OK, i've created allowed.ini that contains allowed .exe." & @CRLF & "Remember ! SHIFT+Alt+d to quit " & @ScriptName)
EndFunc

;/////////////////////////////////////////////////////////////
;//   KILL process not in list
;/////////////////////////////////////////////////////////////
Func XenoKiller()
; List all processes
    local $list = ProcessList()

;/////////////////////////////////////////////////////////////
;//   FOR to find running .exe in my list
;/////////////////////////////////////////////////////////////
    for $i = 1 to $list[0][0]
        Local $linenum = 0              ;This is for skip line in filereadline function
        $file = FileOpen("allowed.ini", 0);open allowed list
        If $file = -1 Then              ; Check if file opened for reading OK
            MsgBox(0, "Error", "Unable to open file.")
            Exit
        EndIf
;/////////////////////////////////////////////////////////////
;//   PROCESS = line read  ?
;/////////////////////////////////////////////////////////////
        While 1
            $linenum = $linenum + 1                                                             ;add one to skip next line
            $line = FileReadLine($file, $linenum)                                               ;each cicle read next line
            if $list[$i][0] = $line Then ExitLoop                                               ;if process name is in my list it's safe, exit to next one
            If @error = -1 Then                                                                 ;if EOF , I can't find in my list
                Run(@ComSpec & " /c " & "pskill -t " & $list[$i][0], "", @SW_HIDE) ;kill him
                ExitLoop                                                                        ;and exit to next one
            EndIf
        Wend
        FileClose($file)
    next
EndFunc

Func Terminate()
    ToolTip("ok, quit " & @ScriptName, 0, 0)
    Sleep(2000)
    Beep(500,250)
    Beep(1000,250)
    Beep(500,250)
    Exit 0
EndFunc

thank you all for your time,

m.

Edited by myspacee
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...