Jump to content

rofl -.- loop ca..


Recommended Posts

This is part of my script.. But even if there is a new process , it wont pop up and tell me .. Maybe its caused by the loop ? Please help

GUICtrlCreateTabItem ( "ProcessDefender" )
GUICtrlCreateLabel ("label0", 30,80,50,20)
$tab0OK=GUICtrlCreateButton ("OK0", 20,50,50,20)
$tab0input=GUICtrlCreateInput ("default", 80,50,70,20)
GUISetState()
_ProcessDefend()
while 1
   Sleep(100)
WEnd


Func _ProcessDefend()
    While 1
    ;Store current processlist "state"
    ;[x][0]: Contains process name
    ;[x][1]: Contains process id
    Global $ListOne = ProcessList()
    
    While 1
        ;[x][0]: Contains process name
        ;[x][1]: Contains process id
        Global $ListTwo = ProcessList()

        ;Verify each process exists in original state
        For $X = 1 To $ListTwo[0][0]
            $found = False

            ;Comparing by PID
            For $Y = 1 To $ListOne[0][0]
                If $ListOne[$Y][1] = $ListTwo[$X][1] Then
                    $found = True
                    ExitLoop
                EndIf
            Next
$newprocessname = _ProcessGetName ( $ListTwo[$X][1] )
            ;If no match is found in ListOne for current process in ListTwo
            If $found = False Then
                $readifAccepted = Iniread("Settings.ini", $newprocessname, "Prar", "Error")
                If $readifAccepted = $newprocessname Then
                    
                Else
                    
                
                WinSetState(_WinGetByPid($ListTwo[$X][1]), "", @SW_DISABLE)
              $processString = "ProcessName: " & $ListTwo[$X][0] & @CRLF
                $processString &= "ProcessID: " & $ListTwo[$X][1] & @CRLF
                
                ;Retrieve process path
                $processString &= "ProcessPath: " & _GetProcessPath($ListTwo[$X][1]) & @CRLF
                
                $processString &= @CRLF & "Allow detected process to remain active?"
                TrayTip("A new process is detected!", "If this is expected, you should allow it to remain active but if you are unsure about it deny it from executing", 5, 1)
                Sleep(1000)
                $result = MsgBox(4 + 48, "ProcessDefender has detected a new process", $processString)
               
                If $result = 6 Then
                    ;This will reset the first comparison state
                    WinSetState(_WinGetByPid($ListTwo[$X][1]), "", @sw_enable)
                    IniWriteSection("Settings.ini", $newprocessname, "Protect=" & $newprocessname)
                    _FileWriteLog ( @scriptdir & "\Logs.txt", "Allowed "& $newprocessname &" from starting in future" )
                    ExitLoop 2
                Else
                    ProcessClose($ListTwo[$X][1])
                    _FileWriteLog ( @scriptdir & "\Logs.txt", "Disallowed "& $newprocessname &" from starting this time" )
                    ExitLoop
                EndIf

            EndIf
            endif
        Next

        ;Check every second
        Sleep(1000)
    WEnd
Wend
    Endfunc
Func _WinGetByPID($iPID, $nArray = 1);0 will return 1 base array; leaving it 1 will return the first visible window it finds
    If IsString($iPID) Then $iPID = ProcessExists($iPID)
    Local $aWList = WinList(), $sHold
    For $iCC = 1 To $aWList[0][0]
        If WinGetProcess($aWList[$iCC][1]) = $iPID And _
                BitAND(WinGetState($aWList[$iCC][1]), 2) Then
            If $nArray Then Return $aWList[$iCC][0]
            $sHold &= $aWList[$iCC][0] & Chr(1)
        EndIf
    Next
    If $sHold Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(1, 0, 0)
EndFunc   ;==>_WinGetByPID


Func _GetProcessPath($GPPpid)
    $colItems = ""
    $strComputer = "localhost"

    $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
    $colItems = $objWMIService.ExecQuery('SELECT * FROM Win32_Process WHERE processid = ' & $GPPpid, "WQL", 0x10 + 0x20)

    If IsObj($colItems) then
        For $objItem In $colItems
            Return $objItem.ExecutablePath
        Next
    Else
       Return ""
    Endif
EndFunc
Func _LiveChat()
    Run("MailSupport.exe")
    Sleep(5000)
    $mailsupportexists = WinExists("ProcessDefender MailSupport")
    If $mailsupportexists = 1 Then
    Else
        MsgBox(0, "Error", "An error has occured while running the MailSupport.."& @CRLF &"It could be caused by the following reasons :"& @CRLF &""& @CRLF &"- User had renamed the MailSupport's main program"& @CRLF &"- User had changed the Add-On's folder name"& @CRLF &"- User is not using Window 2005 and Service Pack1 or above")
        
        Endif
    Endfunc
Link to comment
Share on other sites

Edit.. Now i know what caused the problem..

Notice it, im calling 2 functions

im calling _processdefend() and _detect2000()

and those 2 functions have a loop.

If i call

_processdefend()
_detect2000()

then only the function in the _processdefend func loop will works

how can i make those 2 functions work 2gether (both func have a loop)

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