Ram memory Question? [ SOLVED ]

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Ram memory Question?

#16 Post by Squashman » 24 Sep 2014 13:48

Dos_Probie wrote:Let me clarify a few things with my code, I am running a Windows RT ARM-based PC (only has a sgl sick of 2GB of ram)
and need to do this from pure batch and not powershell or vbs.

But technically you are not using PURE BATCH because you are calling out to WMIC. What is the difference if you use WMIC inside the FOR /F command or Powershell inside the FOR /F command?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Ram memory Question? [ SOLVED ]

#17 Post by Squashman » 24 Sep 2014 13:57

How about good old systeminfo

Code: Select all

H:\>systeminfo | findstr /C:"Total Physical Memory"
Total Physical Memory:     5,072 MB

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: Ram memory Question? [ SOLVED ]

#18 Post by Dos_Probie » 24 Sep 2014 19:15

Squashman wrote:How about good old systeminfo

Code: Select all

H:\>systeminfo | findstr /C:"Total Physical Memory"
Total Physical Memory:     5,072 MB


Yep Or This..

Code: Select all

@Echo Off & SetLocal

echo Via SystemInfo..
echo.
For /F "Tokens=4*" %%G In ('SystemInfo 2^>Nul^|Find ^"Total Physical Memory^"') Do (Set "TPM=%%G")
echo Total Physical Memory:= %TPM% GB
Pause>nul&Exit

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Ram memory Question? [ SOLVED ]

#19 Post by Squashman » 24 Sep 2014 19:26

Dos_Probie wrote:Yep Or This..

Code: Select all

@Echo Off & SetLocal

echo Via SystemInfo..
echo.
For /F "Tokens=4*" %%G In ('SystemInfo 2^>Nul^|Find ^"Total Physical Memory^"') Do (Set "TPM=%%G")
echo Total Physical Memory:= %TPM% GB
Pause>nul&Exit

Well I didn't think I needed to write all the code for you but your code has a minor flaw. Systeminfo outputs in Megabytes and you are stripping that label and putting in Gigabytes.

You don't need to escape the Double Quotes with the find command. You also do not need to put parentheses around the SET command.

Code: Select all

@Echo Off

For /F "Tokens=4" %%G In ('SystemInfo 2^>Nul^|Find "Total Physical Memory"') Do Set /A "TPM=%%G/1024"
echo Total Physical Memory:= %TPM% GB
Pause>nul&Exit

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Ram memory Question? [ SOLVED ]

#20 Post by Compo » 25 Sep 2014 10:30

Just as a follow up, due to the single stick limitation with Dos_Probie's preferred solution, here's an extended version which is intended to total each installed stick then output in both accurate bytes and approximate whole GB.

Code: Select all

@Echo Off
Setlocal
Set Cnt=0
For /F "Skip=1" %%A In ('WMIc MemoryChip Get Capacity') Do Call :Sub %%A
For %%A In (f b) Do (For /F "Tokens=2 Delims==" %%B In ('Set %%ARAM'
   ) Do Set/A %%ARAM+=%%B)
If %bRAM:~-6% NEq %bRAM% Set/A fRAM+=%bRAM:~,-6%
Set tRAM=%fRAM%%bRAM:~-6%
Set "Cnt=(%tRAM% bytes)"
Set/A tRAM=%tRAM:~,-3%/1048576
Echo( Total Installed RAM: %tRAM% GB %Cnt%
Pause>Nul
Exit/B

   :Sub
   If %1' Equ ' GoTo :EOF
   Set/A Cnt+=1
   Set RAM%Cnt%Val=%1
   Call Set "fRAM%Cnt%Val=%%RAM%Cnt%Val:~,-6%%"
   Call Set "bRAM%Cnt%Val=%%RAM%Cnt%Val:~-6%%"
<EDIT>
Changed lines 5 & 6, was:

Code: Select all

For /F "Tokens=2 Delims==" %%A In ('Set fRAM') Do Set/A fRAM+=%%A
For /F "Tokens=2 Delims==" %%A In ('Set bRAM') Do Set/A bRAM+=%%A
</EDIT>
<EDIT2>
Changed line 10, was:

Code: Select all

Set/A tRAM=(%tRAM:~,-3%+1048576/2)/1048576
</EDIT2>
Last edited by Compo on 26 Sep 2014 05:40, edited 2 times in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Ram memory Question? [ SOLVED ]

#21 Post by foxidrive » 25 Sep 2014 10:37

Compo wrote:here's an extended version which is intended to total each installed stick then output in both accurate bytes and approximate whole GB.


Looks good here - in a 32 bit Win 8.1 OS. I do have 8 GB.


Total Installed RAM: 8 GB (8589934592 Bytes)

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Ram memory Question? [ SOLVED ]

#22 Post by Compo » 25 Sep 2014 10:57

Thanks for the confirmation foxidrive, some things are not feasible to test in my virtual machine.
(I've also changed the code slightly to make it more appealing to my eye.)

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: Ram memory Question? [ SOLVED ]

#23 Post by Dos_Probie » 25 Sep 2014 18:39

Thanks for working on this and the updated wmic script Compo..
My Arm system single slot ram is now reading correct as 2 GB and my dual slot lap of windows 8 also is correct showing 16 GB but my desktop which has four sticks of 8 GB each is showing (Total Installed RAM: 33 GB (34359738368 Bytes)) instead of 32 GB.
~DP

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Ram memory Question? [ SOLVED ]

#24 Post by Compo » 26 Sep 2014 05:44

Dos_Probie wrote:my desktop which has four sticks of 8 GB each is showing (Total Installed RAM: 33 GB (34359738368 Bytes)) instead of 32 GB.
~DP
The incorrect whole GB is an unfortunate result of having to approximate using batch arithmetic. If you look at the number of bytes, you will note that they are exactly correct for 32GB.

As a result of the approximation I identified that the original code was accurate up to 20 GB of RAM, I have edited the code in order for it to be accurate up to 41 GB of RAM

If you have an amount below 1 GB or above 41 GB the readout for GB will not be correct

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: Ram memory Question? [ SOLVED ]

#25 Post by Dos_Probie » 26 Sep 2014 07:52

Thanks Compo for the updated Wmic script allowing for larger RAM, my Desktop now shows as "Total Installed RAM: 32 GB (34359738368 bytes)", And as I am sure you already know you can also use Systeminfo (about 3-5 sec delay) which calcultes your total ram in MB..and also works on both ARM and Non-ARM platforms as well.
~DP :)

Code: Select all

@Echo Off&Setlocal&Title, Total Installed Ram Info
Echo(Via SystemInfo in MB/..
Echo.
For /F "Tokens=4" %%A In ('SystemInfo 2^>Nul^|Find "Total Physical Memory"') Do Set tRAM=%%A
Echo(Total Installed RAM: %tRAM%.0 MB
Pause>Nul
Exit/B

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Ram memory Question? [ SOLVED ]

#26 Post by Compo » 26 Sep 2014 09:17

Dos_Probie wrote:And as I am sure you already know you can also use Systeminfo (about 3-5 sec delay) which calcultes your total ram in MB..and also works on both ARM and Non-ARM platforms as well.
~DP :)
Image
The trouble I have with that solution, (apart from the delay), is that it outputs the wrong amount in MB and in the case on the PC I've just tried it on also doesn't look correct with an included comma. (I don't think decimal precision will be warranted for any outputs on this task).

It should read, Total Installed RAM: 4096 MB

Dos_Probie
Posts: 233
Joined: 21 Nov 2010 08:07
Location: At My Computer

Re: Ram memory Question? [ SOLVED ]

#27 Post by Dos_Probie » 26 Sep 2014 11:43

Yeah the delay is slow compared to the instant results of Wmic..You can always use the Set command with /A switch to output in GB, Which works when using multi-bank memory.
~DP

Code: Select all

Echo(Via SystemInfo in GB/..
For /F "Tokens=4" %%A In ('SystemInfo 2^>Nul^|Find "Total Physical Memory"') Do Set /A tRAM=%%A
Echo(Total Installed RAM: %tRAM%.0 GB
Pause>nul
Exit/B

Post Reply