JSI Tip 9757. How can I retrieve the physical memory in a batch, using built-in commands?

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
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%

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.