Sign in to follow this  
Followers 0
cypher175

Get Location + PID of Processes..??

6 posts in this topic

How could I get the Locations + PID of multiple running processes with the same name..??

If 5 processes are running that all have the same name, but each are located in different locations.. How can I get the location + PID for each of those processes..??

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

#Include <WinAPIEx.au3>

$List = ProcessList('notepad.exe')
If Not @error Then
    For $i = 1 To $List[0][0]
        ConsoleWrite($List[$i][0] & '   ' & $List[$i][1] & '   ' & _WinAPI_GetModuleFileNameEx($List[$i][1]) & @CR)
    Next
EndIf

WinAPIEx.au3

Edited by Yashied

Share this post


Link to post
Share on other sites

thanks for the code example..

What if there are multiple instances of the same AutoItExe Process running simultaneously and I need to get the PID of the 1st executed AutoItExe so i can close all the other instances and only have the 1st executed AutoItExe continue to run..??

Share this post


Link to post
Share on other sites

For this scenario, you may also wish to use the _Singleton() function of the Misc.au3 UDF.

For more advanced scenarios, you could also try WMI:

Local $objWMI = ObjGet("winmgmts:\\localhost\root\CIMV2")
Local $objItems = $objWMI.ExecQuery('SELECT ProcessId,ExecutablePath,CreationDate FROM Win32_Process WHERE ExecutablePath LIKE "%process_name%"', "WQL", 0x10 + 0x20)
If IsObj($objItems) Then
For $objItem In $objItems
    ConsoleWriteError("PID:" & $objItem.ProcessId & " NAME:'" & $objItem.ExecutablePath & "' DATE:" & $objItem.CreationDate & @CRLF)
;;handling code goes here
Next
EndIf

See This MSDN Article for the functional meaning of each property.

You could add each process onto a 2-dimensional array and sort by the CreationDate to get the earliest process and kill the others.

Share this post


Link to post
Share on other sites

cypher175, ProcessList will give you a list in the order the processes started. So at row[1] will be the first created process and row[last] will be the last created process. However, the current running process used to execute ProcessList() may or may not show up depending on the timing.. which is why you'd want to compare it against the current running process ID (@AutoItPID).

Share this post


Link to post
Share on other sites

Is there any way to get the Parent PID of the @AutoItPID..??

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