In tip 9756, I described 3 methods of retrieving the physical memory in a batch, but they each used some free add-on software.

Using the built-in %SystemRoot%\System32\WinMSD.exe, I have scripted TPMem.bat to return the physical memory in megabytes.

The syntax for using TPMem.bat is:


Where RAM is a call directed numeric environment variable that will contain the physical memory in megabytes.

TPMem.bat contains:

                              @echo off                              if \{%1\}==\{\} @echo Syntax: TPMem RAM&goto :EOF                              setlocal ENABLEDELAYEDEXPANSION                              winmsd /categories SystemSumary /report "%TEMP%\TotalPhysicalMemory.tmp"                              for /f "Tokens=*" %%a in ('type "%TEMP%\TotalPhysicalMemory.tmp"^|Find "Total Physical Memory"') do (                               for /f "Tokens=4" %%x in ('@echo %%a') do (                                set mem=%%x                               )                               set mem=!mem:.=!                               set mem=!mem:,=!                               set /a mem=!mem!+50                               set /a mem=!mem!/100                              )                              endlocal&set /a %1=%mem%