JSI Tip 9756. How can I retrieve the physical memory in a batch?

Using memory.exe freeware, you can use the following command to set the mem numeric environment variable to the physical memory in bytes:

for /f "Tokens=*" %%a in ('memory /s') do set /a mem=%%a
You can use memupsec.bat to return the physical memory in kilobytes.

Using PsInfo.exe freeware, 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
for /f "Tokens=*" %%a in ('psinfo^|Find "Physical memory:"') do (
 for /f "Tokens=3" %%x in ('@echo %%a') do (
  set /a mem=%%x
endlocal&set /a %1=%mem%

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.