Jump to content

Way to get physical memory


JohnOne
 Share

Recommended Posts

MemGetStats() returns incorrect amount for me.

Is there another more accurate method about?

I have looked, and might have missed a post amid all the game threads associated with memory.

MsgBox(0,"",_Mem())

Func _Mem()
    $a = MemGetStats()
    $a = Round($a[1] / 1024)
    Return $a & " MB"
EndFunc

EDIT:

returns 992 for me or 1015 when / 1000, with 1GB ram.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Try this:

#AutoIt3Wrapper_UseX64=n

MsgBox(0, "Physical Memory", "Physical Memory installed: " & Round(GetMemWMI() / 1024 ^2, 0) & " MB")

Func GetMemWMI($srv = "localhost")
    Local $mem, $colItems, $colItem, $ping, $x
    $ping = Ping($srv)
    If $ping Then
        $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $srv & "\root\cimv2")
        $colItems = $objWMIService.ExecQuery("Select Capacity from Win32_PhysicalMemory", "WQL", 0x30)
        If IsObj($colItems) Then
            For $objItem In $colItems
                $mem += $objItem.Capacity
            Next
            Return SetError(0, 0, $mem)
        Else
            Return SetError(2, 0, 0)
        EndIf
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc

I'm sure that there is a kernel32.dll version flying around...

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

ask manager reports 991 MB

Cheers UEZ, that seems to get it, speed is not really an issue against accuracy for me.

Just had to change

Round(GetMemWMI() / 1024 ^2, 0) & " GB")

To

Round(GetMemWMI() / 1024 ^3, 0) & " GB")

Unless I have 1024 GB :)

Anyway it reports 1 GB which is what I was after, just wondering if it will be ok on 64 bit OS.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

ask manager reports 991 MB

Cheers UEZ, that seems to get it, speed is not really an issue against accuracy for me.

Just had to change

Round(GetMemWMI() / 1024 ^2, 0) & " GB")

To

Round(GetMemWMI() / 1024 ^3, 0) & " GB")

Unless I have 1024 GB ;)

Anyway it reports 1 GB which is what I was after, just wondering if it will be ok on 64 bit OS.

GetMemWMI() / 1024 ^2 is MB and not GB :)

It is also working properly when compiling it as x64 application.

Br,

UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Windows Vista SP1 and later also has the function GetPhysicallyInstalledSystemMemory (<-- link) in Kernel32.dll

MsgBox(0, "Title", "GetPhysicallyInstalledSystemMemory = " & _GetPhysicallyInstalledSystemMemory())

Func _GetPhysicallyInstalledSystemMemory()
    $aRet = DllCall("Kernel32.dll", "int", "GetPhysicallyInstalledSystemMemory", "int*", "")
    If @error Then Return SetError(1, 0, 0)
    Return $aRet[1]
EndFunc
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...