/*

Usage: $proguptime(name|wildcarded name [,N)[.name]

* Returns the uptime of the specified process.
* Process may contain wildcards * and ?
* The N will reference the Nth process. If N is 0 it returns the total number of matches.
* The property .name is optional, when used it will return a result in the form of "<name of process> <uptime>", which is handy when using wildcards to see which process it actually referenced.

Examples:

$proguptime(win*.ex?,1).name
$proguptime(notepad.exe,2)
$proguptime(*,0)

Minimum requirements:

mIRC 6.16
Windows 2000 Professional or higher

*/

Code:
alias proguptime {
  var %a = $$1 $+ $ticks, %b = b $+ %a, %c = creationdate,name
  .comopen %a WbemScripting.SWbemLocator
  if ($comerr) return COM Error
  .comclose %a $com(%a,ConnectServer,1,dispatch* %b) 
  if ($com(%b)) .comclose %b $com(%b,ExecQuery,1,bstr*,SELECT %c FROM $&amp;
    Win32_Process WHERE name LIKE $+(",$replace($1,*,%,?,_),"),dispatch* %a)
  if (!$com(%a)) return COM Error
  %c = $iif($prop == name,$comval(%a,$2,name))
  %b = $comval(%a,$iif($2 isnum 0-,$2,1),creationdate)
  .comclose %a
  if (%b) return $iif(!$2,%b,%c $msdate(%b))
}

alias msdate {
  return $duration($calc($ctime - $ctime($+($left($$1,4),-,$mid($1,5,2),-, $&amp;
    $mid($1,7,2) $mid($1,9,2),:,$mid($1,11,2),:,$mid($1,13,2)))))
}


Note that WMI is generally slow to perform queries, so I do not recommend calling this identifier too many times in a row to loop through it. One other possibly better way would be to do a query on all processes, add the entries to a hash table, and loop through that. Though, check how it performs with this code first and let me know how it goes. One other way would be that when you specify 0, that i return all matching processes along with their uptime in 1 string, so you can loop through that with $gettok or something.


Gone.