Jump to content

Retrive RAM size


OmYcroN
 Share

Recommended Posts

How can i retrive the RAM installed on a system in Autoit ? I've tried reading the registry RegRead("HKEY_LOCAL_MACHINE\HARDWARE\RESOURCEMAP\System Resources\Physical Memory", ".Translated")

but i don t know how to handle the result (REG_RESOURCE_LIST). Also with command promt it can be done but i need this in a variable not on an external file/program. Is there another way to do this ?

Link to comment
Share on other sites

  • 8 months later...

10x, i m stupid ... >_<

I know this post is ancient, but I've been trying to get this value for a while

Here's what I came up with after a great deal of research/internet trawling...

;Use REG command because RegRead cannot handle REG_RESOURCE_LIST values
;Grab last 8 characters, strip spaces from end of string
$Memory = StringRight(StringStripWS(_RunCommand("REG QUERY ""HKLM\HARDWARE\RESOURCEMAP\System Resources\Physical Memory"" /v .Translated"),2),8)

;Convert to Decimal( Trim to Hex value ) *Multiply
Dim $RAM[5]
$RAM[0] = Dec(StringTrimLeft                ($Memory,6))    *16777216
$RAM[1] = Dec(StringTrimRight(StringTrimLeft($Memory,4),2)) *65536
$RAM[2] = Dec(StringTrimRight(StringTrimLeft($Memory,2),4)) *256
$RAM[3] = Dec(StringTrimRight               ($Memory,6))
$RAM[4] = $RAM[0]+$RAM[1]+$RAM[2]+$RAM[3]   ;Added values = RAM in BYTES

MsgBox(0,"",$RAM[0]&" "&$RAM[1]&" "&$RAM[2]&" "&$RAM[3]& @CRLF&@CRLF&_StringConvertBytes($RAM[4]))


;Run DOS command, Output to StdOut
Func _RunCommand($Command, $Username1="",$Password1="")
    Local $CommandRun, $CommandOutput
    ConsoleWrite("---------------"&@CRLF&"Command:"&@CRLF&$Command&@CRLF)
    If $Username1 <> "" And $Password1 <> "" Then 
        $CommandRun = RunAs($Username1,"AD",$Password1,0,@ComSpec&" /c "&$Command, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    Else
        $CommandRun = Run(@ComSpec&" /c "&$Command, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    EndIf
    $CommandOutput = ''
    While 1
        $line = StdoutRead($CommandRun)
        If $Line = "" Then $line = StderrRead($CommandRun)
        If @error Then ExitLoop
        If $line <> '' Then $CommandOutput &= $line
    Wend
    ConsoleWrite("Returned:"&@CRLF&$CommandOutput&@CRLF&"----------------")
    Return $CommandOutput
EndFunc

;Convert String value to kb, mb, gb etc
Func _StringConvertBytes($bytes,$rounding = 2, $outputstring = True)
    Local $array[3]
    Select
        Case $bytes < 2^10 ;bytes
            $array[0] = $bytes
            $array[1] = "bytes"
            $array[2] = "bytes"
        Case $bytes >= 2^10 and $bytes < 2^20 ;kilobytes
            $array[0] = Round($bytes/2^10,$rounding)
            $array[1] = "kilobytes"
            $array[2] = "Kb"
        Case $bytes >= 2^20 and $bytes < 2^30 ;megabytes
            $array[0] = Round($bytes/2^20,$rounding)
            $array[1] = "megabytes"
            $array[2] = "Mb"
        Case $bytes >= 2^30 and $bytes < 2^40 ;gigabytes
            $array[0] = Round($bytes/2^30,$rounding)
            $array[1] = "gigabytes"
            $array[2] = "Gb"
        Case $bytes >= 2^40 and $bytes < 2^50 ;terabytes
            $array[0] = Round($bytes/2^40,$rounding)
            $array[1] = "terabytes"
            $array[2] = "Tb"
        Case $bytes >= 2^50 and $bytes < 2^60 ;petabytes
            $array[0] = Round($bytes/2^50,$rounding)
            $array[1] = "petabytes"
            $array[2] = "Pb"
        Case $bytes >= 2^60 and $bytes < 2^70 ;exabytes
            $array[0] = Round($bytes/2^60,$rounding)
            $array[1] = "exabytes"
            $array[2] = "Eb"
        Case $bytes >= 2^70 and $bytes < 2^80 ;zettabytes
            $array[0] = Round($bytes/ 2^70,$rounding)
            $array[1] = "zettabytes"
            $array[2] = "Zb"
        Case $bytes >= 2^80 ;yottabytes
            $array[0] = Round($bytes/ 2^80,$rounding)
            $array[1] = "yottabytes"
            $array[2] = "Yb"
    EndSelect
    If $outputstring then 
        Return $array[0] & " " & $array[2]
    Else
        Return $array
    EndIf
EndFunc  ;==>_StringConvertBytes
Link to comment
Share on other sites

I know this post is ancient, but I've been trying to get this value for a while

Here's what I came up with after a great deal of research/internet trawling...

Why didn't you use MemGetStats() as suggested in this thread?

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Why didn't you use MemGetStats() as suggested in this thread?

I needed a reliable way of getting information (RAM, DiskSize, FreeSpace) from a Remote machine without WMI installed, and I've enjoyed the challenge of finding out how to get the majority of information I need the old fashioned way >_<

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...