getting PC RAM info

Started by jm0000, January 30, 2018, 08:27:58 AM

Previous topic - Next topic

jm0000

Hi,

    I am trying to write a PC inventory program.  I'm stuck on getting the amount of RAM. It thought this was going to be an easy process, but I can't get it to work.  I used WMI to gt the ram, but it reports it as:  8456130560 [ for 8 GIG] . I thought no problem. I'll just divide  8456130560 by 1024/1024/1024 and round to the second decimal point, but this has been more difficult that I thought.  I would image that someone by now had the same issue.  Here is a sample of a code I got from your web page, and was trying to modify it.

;get total memory
Locator = ObjectOpen("WbemScripting.SWbemLocator")
   Service = Locator.ConnectServer()
   Security = Service.Security_     
   Security.ImpersonationLevel = 3
   Class = "Win32_ComputerSystem"  ; Holds total memory info
   Instance = Service.InstancesOf(Class)

   Enum = ObjectCollectionOpen(Instance)
   

   While 1
   Obj = ObjectCollectionNext(Enum)
   
      If Obj == 0 Then Break
ram=obj.TotalPhysicalMemory     ;this is the total ram
   EndWhile
   
   ObjectCollectionClose(Enum)
   ObjectClose(Instance)
   ObjectClose(Security)
   ObjectClose(Service)
   ObjectClose(Locator)

   ;display the total ram
      message("Total ram = ",RAM)
   
;convert to  gig
   GB=1024*1024*1024 ; <--- this calculation works.

   message("GB ", GB) ;<-- Display correct number

tram = Int( RAM / GB)   ; <--  This is not providing the right answer? Maybe number is to big?

  message("Total ram = ",tRAM) ;Displays 0?






td

The number 8456130560 is greater than the largest 32-bit signed integer so you need to use floating point number or the hugh math extender instead.

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

jm0000

Ok thanks. I wrote a PS to get the information, and then pass the my winbatch file.

td

All you need is something like the following:   

Code (winbatch) Select
Gb = (1024**3)*1.0
GigRam = ram / Gb


in your WMI script.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade