Sign in to follow this  
Followers 0
MadBoy

Help with process handling

3 posts in this topic

Hey,

Here's my problem. I force Plug & Play to redetect devices. Then i monitor processes for process rundll32.exe to know if the process has terminated then i know that detection process is done. Now problem is rundll32.exe is often used by other calls so often rundll32.exe can be in process manager more then once.

So i decided to write little function that is run before Plug & Play is started and checks if rundll32.exe is running. If it is it adds their PID to array.

$process_list = ProcessList("rundll32.exe")
    For $i = 1 To $process_list[0][0]
        _AddLineBox("Found process " & $process_list[$i][0] & " with PID " & $process_list[$i][1] & ". Ignoring that process!")
        _ArrayAdd($ArrayPid, $process_list[$i][1])
    Next
oÝ÷ ØéÊz0IèÃZ´ò².Ù÷öÖÞµ©)í¡Ê'²'^­«b¢wè¬òÔ©©

Thanks :lmao:


My little company: Evotec (PL version: Evotec)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Something like this:

Func _SearchArray (ByRef $aArray, $qString)
    For $x = 1 to UBound ($aArray) - 1
        If StringInStr ($aArray[$x], $qString) <> "" Then
            Return $x
            ExitLoop
        EndIf
    Next
    Return 0
EndFunc

$time_to_wait = 15

For $time_waited = 1 To $time_to_wait
    Sleep (1000)

    $process_list = ProcessList("rundll32.exe")
    For $i = 1 To $process_list[0][0]
        If _SearchArray ($ArrayPid, $process_list[$i][1]) = 0 Then
            If $debug = "Yes" Then _AddLineBox("DEBUG: Program found the process (" & $process_list[$i][1] & ") and now awaits for it to terminate.")
            ProcessWaitClose($process_list[$i][1])
            _AddLineBox("System has now finished installing drivers for your hardware. Enjoy!")
            ExitLoop 2
        EndIf
    Next
    
    If $time_waited = $time_to_wait Then
        _AddLineBox("No active plug & play process has been found after " & $time_to_wait & " seconds. Terminating.")
    EndIf
Next

There's probably a cleaner way to do the waiting loop but it's all I can think of at the moment.

Edited by ChiDragon

Share this post


Link to post
Share on other sites

Tnx, that should do it :lmao: I saw it yesterday when it was little bit diffrent and i thought over night how to make it better with like loop Until or so.. but I see you fixed it so :ph34r: TNX! I had it going in my head for a while just i couldn't put it on paper :geek:


My little company: Evotec (PL version: Evotec)

Share this post


Link to post
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
Sign in to follow this  
Followers 0