Jump to content

Processfindprocessfirst/next


Valik
 Share

Recommended Posts

I've just finished writing these 2 functions. I gave them those name styles to be consistent with FileFindFileFirst/Next, though this enumeration method works a little different. PFPFirst just takes a system snapshot and stores it, any subsequent calls to PFPNext will just enumerate through that automatically and return the next 2 element array of Process name(0), PID(1). If it reaches the end, then the memory for the snapshot will be freed and all calls to PFPNext will set @error. If there is already a snapshot and PFPFirst is called again, it'll overwrite the original snapshot.

One thing I noticed which is minor: The Toolhelp32 method returns more processes. It will return every process except "System Idle Process". The PSAPI method will return less, but all those it wouldn't return are critical system processes. I also had to fiddle with the OpenProces access rights a bit which makes me wonder how the PSAPI version of Util_DoesProcessExist works at all (With all access, it wouldn't touch system processes...)

Example usage:

ProcessFindProcessFirst()
If Not @error Then
    While 1
        $proc = ProcessFindProcessNext()
        If @error Then ExitLoop
        MsgBox(4096, "", "name=" $proc[0] & @LF & "pid=" & $proc[1])
        $count = $count + 1
    WEnd
EndIf
MsgBox(4096, "", "Count=" & $count)

Edit: Fixed the function names in the code example, they were using my testing names which were shortened.

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