Sign in to follow this  
Followers 0
JohnOne

Way to get physical memory

11 posts in this topic

#1 ·  Posted (edited)

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.

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Yes, I did that and Ceiling, except I dont want what task manager reports, I want the amount of physical memory slotted into my memory banks, that is 1GB.

You are best off reading out of the WMI then, as posted earlier.

Share this post


Link to post
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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
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

Share this post


Link to post
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
Sign in to follow this  
Followers 0