viewpoint-particle

Author Topic: getting PC RAM info  (Read 85 times)

jm0000

  • Newbie
  • *
  • Posts: 7
getting PC RAM info
« on: January 30, 2018, 08:27:58 am »
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

  • Tech Support
  • *****
  • Posts: 2349
    • WinBatch
Re: getting PC RAM info
« Reply #1 on: January 30, 2018, 10:48:49 am »
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.

 
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


jm0000

  • Newbie
  • *
  • Posts: 7
Re: getting PC RAM info
« Reply #2 on: February 01, 2018, 09:58:24 am »
Ok thanks. I wrote a PS to get the information, and then pass the my winbatch file.

td

  • Tech Support
  • *****
  • Posts: 2349
    • WinBatch
Re: getting PC RAM info
« Reply #3 on: February 01, 2018, 10:17:45 am »
All you need is something like the following:   

Code: Winbatch
Gb = (1024**3)*1.0
GigRam = ram / Gb

in your WMI script.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates