Jump to content

Getting most recent process


Recommended Posts

Say I had 2 processes named "Process.exe" and "Process.exe".

Using

ProcessList("Process.exe")

would give me both of them along with their PIDs.

I need to determine which one has been running longer. How can I achieve this? (I assume with winmgmts and ExecQuery)

My code (It's not much):

$Processes = ProcessList("Process.exe")
Local $Times[$Processes[0][0]]

For $P = 1 To $Processes[0][0]
    $Times[$P-1] = ;Get how long process has been running.
Next

;Code to sort it or split strings if in a HH:MM:SS format or whatever. (I'm not sure what format it will be in)
;This part is easy once I have the times.
Link to comment
Share on other sites

Well, the way I would go about doing it would be getting a command line process viewer, and using that to get the creation time for the two processes with Run().

Of course there's probably a wmi/WINAPI option that I don't know about, but I come from a *nix background and I tend to go with the 'call the small utility' approach to problem solving.

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

Look at _ProcessListProperties(). The process creation Date/Time is listed in [n][8] of the array.

:)

Edit: Ooh. I like the DLL calls in the WinAPIEx UDF. The _ProcessListProperties() function is all WMI.

:(

Edited by PsaltyDS
Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Thanks, but I'd rather go with a winAPI option.

Fair enough, I'm glad you seem to have found what you were looking for :(

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

Here's the relevant working part of my code:

$Processes = _ProcessListProperties("Process.exe")
Local $String = "Select Process" & @CRLF

If $Processes[0][0] > 1 Then
    For $X = 1 To $Processes[0][0]
        $String &= $X & ") PID:" & $Processes[$X][1] & @CRLF & "    ---Created: " & $Processes[$X][8] & @CRLF
    Next

    $Index = InputBox("Select Process", $String, "1")
    If @error = 1 Then Exit

    Run("Run.exe " & $Processes[$Index][1])
ElseIf $Processes[0][0] = 1 Then
    Run("Run.exe " & $Processes[1][1])
EndIf

Thanks for the help. By the way, when you guys posted those functions, I didn't realize they weren't in the Help File. I felt really stupid at first because I thought they were in there. :(

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