Based on some testing and code modifications I've taken the core code from Glenn's Memory() UDF which has also been modified with updates from myself and Al_Po and some from the discussion here: Detect amount of RAM / memory

Glenn's original Memory UDF
Memory() - Get Physical RAM size - local or remote

Here are the items looking to improve.

  • A.) Better method to correct UNC or confirmation code functions correctly as is
  • B.) Code must derive memory size from both local and remote registry read, not from COM methods
  • C.) Looking to reduce code size by better methodolgy if it exists, but not for the sheer sake of reducing to unreadable code like Golfing produces.
  • D.) Ensure that all possible errors are properly returned to the calling script
  • E.) A normal user should be able to run it during logon as well


i.e. If, as was said in the discussion in the other thread, there is un-needed bloat, can it be removed by using cleaner/smaller/tighter code not just character size reduction. As it is, Glenn's code appears to be about the only properly working code with various memory tests.

Lonkero's UDF MemSize() - returns installed memory size appears to work locally.


Function Memory(Optional $sComputer)

Dim $MemKey, $HexDmp, $Pointer, $Counter, $Start, $Hex, $HVal, $Hex2Dec
$MemKey = 'HKLM\Hardware\ResourceMap\System Resources\Physical Memory'
;Correct any UNC paths if supplied or missing
$MemKey = IIf((Not $sComputer), $MemKey,('\\'+Join(Split($sComputer,'\'),'',3)+'\'+$MemKey))
; Get the memory value from the registry
$HexDmp = ReadValue($MemKey, '.Translated')
; Check for invalid read and Return
If Not $HexDmp
$Memory = @ERROR Exit $Memory
EndIf
If Len($HexDmp) = 0
$Memory = 1 Exit $Memory
EndIf
; Prepare the array
Dim $HVals[((Len($HexDmp) / 32) - 2)]
$Pointer = 0
; Resequence the bytes in the HexDump, starting in the 65th position,
; and take 8 bytes every 32 bytes
For $Start = 65 To Len($HexDmp) Step 32
$Hex = ''
For $Counter = 6 To 0 Step -2
$Hex = $Hex + SubStr($HexDmp, $Start + $Counter, 2)
Next
; Load the hex value into the array and increment position
$HVals[$Pointer] = $Hex
$Pointer = $Pointer + 1
Next
; Now have an array of hex values representing installed physical RAM
For Each $HVal In $HVals
$Hex2Dec = 0.0
While $HVal
$Hex2Dec = 16.0 * $Hex2Dec + Execute('Exit &' + Left($HVal ,1))
$HVal = SubStr($HVal ,2)
Loop
$Memory = $Memory + CDbl($Hex2Dec) / 1024
Next
$Memory = Int(($Memory + 648) / 1024)
If ($Memory Mod 2)=1
$Memory = $Memory+1
EndIf
EndFunction



Edited by NTDOC (2005-02-24 06:12 AM)