In a [System.Diagnostics.Process] collection, can I determine the most recently active procces?

  Kiến thức lập trình

Usually with get-process, its mainWindowTitle property gives me the most recently active window, that is the window that is highest in the ‘Z order’ (for the process passed to get-process). So this question rarely rises.

But more and more, I am dealing with applications that spawn a process for each window it has:

 NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
 ------    -----      -----     ------      --  -- -----------
     32   106.21     139.10       0.61   16744   1 PureRef
     32    84.71     122.95       0.50   23588   1 PureRef
     32    87.88     121.03       0.53   28076   1 PureRef

I want to get the process objects in the order the PureRef windows are currently in, on the windows Z order, or even have some way of querying this. Looking at all of the properties for get-process, startTime is the only property dealing with date/time.

The reason why I need this, is that often, window titles have in them file paths, so (Get-Process -Name PureRef).MainWindowTitle:

(Get-Process -Name PureRef).MainWindowTitle

Level Design 1 - PureRef - C:tempLevel Design 1.pur
Car Shelf - PureRef - C:tempCar Shelf.pur
Backgrounds_1 - PureRef - C:tempBackgrounds_1.pur

and I would like to write simple generic commands such as Get-Pureref, that will return a list of paths in the most recently used windows order, so Get-PureRef so should do:

C:tempLevel Design 1.pur
C:tempCar Shelf.pur
C:tempBackgrounds_1.pur

Its critical for me to have this order so that something like (Get-PureRef)[0] | <Do-Something> always means I am operating on the most recent windows file, which is a typical convention on my system already.

I am on PWSH 7.4

LEAVE A COMMENT