Welcome

User: Pass:   register



;   Usage:   $memuse(process, N [, kmgt3])[.suf]
;
;   Author:  FiberOPtics
;
;   Email:   mIRC.FiberOPtics@gmail.com
;
;
;   Description:
;   ------------
;   This snippet will return the memory usage of a running process.
;   These values can be seen in the tab "Processes" from the "Windows Task Manager",
;   under the column "Mem Usage". The output is by default in bytes, though can be
;   formatted differently by specifying a third parameter. When specifying the .suf 
;   property, the result will have the formatting unit appended to the result.
;
;
;   Parameters:
;   -----------
;   Required $1 = name of the process as seen in the Process list
;   Required $2 = references Nth instance of the specified process
; 
;      --> N = 0 : returns total memory usage of all instances together
;      --> N = 1 : returns memory usage of the first instance
;      --> ...
; 
;   Optional $3 = parameters from the built-in $bytes identifier, to format
;                 the output: bkmgt3
;   
;
;   Examples:
;   ---------
;   //echo -a $memuse(mirc.exe ,0) -> returns total mem usage of all instances of mIRC in bytes
;   //echo -a $memuse(winamp.exe, 1, m) -> returns mem usage of 1st instance of Winamp in megabytes
;   //echo -a $memuse(notepad.exe, 2, k).suf -> returns mem usage of 2nd instance of Notepad in kilobytes
;   
;
;   Requirements
;   -------------------
;   mIRC 6.16 because of $comval
;
;   Works by default on Windows versions: Vista, XP, 2000 Professional, or NT Workstation 4.0 SP4 
;
;   Windows 95 and 98 users can't use WMI, unless if they download the WMI
;   core from http://www.microsoft.com/downloads
; 
;   For more info about WMI and its requirements check the url:
;   http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/wmi_start_page.asp
;
;
;   Updates:
;   --------
;   * Recoded alias completely
;   * Added property .suf to show formatting when specified
;   * Added :error label for cleanup in case of error
;   * Added version check to see if mIRC is atleast version 6.16
;

alias memuse {
  if (!$isid) {
    echo -ac info * $!memuse: this alias can only be called as an identifier.
    return 
  }
  var %e = return $+($chr(3),$color(info),*) $!memuse: 
  if ($version < 6.16) %e this alias can only be used on mIRC versions 6.16 or higher.
  if ($0 < 2) %e insufficient parameters.
  if ($2 !isnum 0-) %e The N property can only be a positive integer. 
  if ($0 > 2) && ($3 !isin bkmgt3) %e unexisting parameter $3 for $!bytes.
  if ($prop != $null) && ($prop != suf) %e property can only be .suf
  var %loc = loc $+ $ticks, %wmi = wmi $+ $ticks, %col = col $+ $ticks
  .comopen %loc WbemScripting.SWbemLocator
  if ($comerr) %e Error opening locator object.
  .comclose %loc $com(%loc,ConnectServer,1,dispatch* %wmi) 
  if (!$com(%wmi)) %e Error connecting to wmi.
  .comclose %wmi $com(%wmi,ExecQuery,1,bstr*,SELECT WorkingSetSize $&
    FROM Win32_Process WHERE Name = $+(",$1,"),dispatch* %col) 
  if (!$com(%col)) %e Error retrieving collection.
  if ($comval(%col,0) == 0) { .comclose %col | %e no such process $1 }
  var %i = 1, %result
  while ($comval(%col,%i,WorkingSetSize) != $null) { 
    %result = %result + $v1 
    inc %i 
  }
  .comclose %col
  return $bytes($calc($gettok(%result,$iif(!$2,1-,$2),43)),$iif($3,$3,b)). [ $+ [ $prop ] ]
  :error
  tokenize 32 %loc %wmi %col
  scon -r if ($com( $* )) .comclose $*
}






© 1996-2010 hdesk.org and dalnethelpdesk.com