Jump to content

Get Location + PID of Processes..??


Recommended Posts

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

Link to comment
Share on other sites

#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
Link to comment
Share on other sites

  • 2 weeks later...

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

Link to comment
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.

Link to comment
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).

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