;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       WMIMemory()  
;;  
;;AUTHOR         Glenn Barnas 
;;  
;;ACTION         Returns the amount of Physical RAM in a local or remote system   
;;  
;;VERSION        1.0  - 2007/04/26 
;; 
;;HISTORY        1.0  - 2007/04/26 - Initial Release 
;;  
;;SYNTAX         Memory([Target] [,WMIAuthPtr]) 
;;  
;;PARAMETERS     Target - OPTIONAL - String 
;;               - The name of system to query. Default is local system  
;; 
;;               AuthPtr - OPTIONAL - Object 
;;               - The pre-authenticated WMI object pointer. 
;;               Use WMIAuthenticate() udf to create the AuthPtr value. 
;;               AuthPtr is not needed if user has admin rights. 
;;  
;;REMARKS        Returns RAM size using WMI value - more accurate than registry where supported 
;;  
;;RETURNS        Installed Physical RAM (in Megabytes)  
;;  
;;DEPENDENCIES   None  
;;  
;;TESTED WITH    Win2K, WinXP, Win2K3  
;;               Tested with up to 8G of RAM  
;;  
;;EXAMPLES       $RAM = WMIMemory('ThatPC')  
;;  
; 
Function WMIMemory(Optional $_Computer, OPTIONAL $_pAuth)
 
  Dim $_objWMIService, $_colItems, $_objItem	; WMI object vars 
  Dim $_M					; memory calculation var 
 
  ; insure a properly formatted computer name, default to local computer is not specified 
  $_Computer = IIf(Not $_Computer, '.', Join(Split($_Computer,'\'),''))
 
  ; If a pre-authenticated WMI object pointer was provided, use it, otherwise create a new object pointer 
  If $_pAuth
    $_objWMIService = $_pAuth
  Else
    $_objWMIService = GetObject('winmgmts:{impersonationLevel=impersonate}!\\' + $_Computer + '\root\cimv2')
    If @ERROR Exit Val('&' + Right(DecToHex(@ERROR), 4)) EndIf
  EndIf
 
  $_colItems = $_objWMIService.ExecQuery("Select * from Win32_MemoryArray",,48)
  For each $_objItem in $_colItems
    $_M = (Val($_objItem.EndingAddress) + 1.0) / 1024
  Next
 
  $WMIMemory = $_M
  Exit @ERROR
 
EndFunction