Skip navigation

JSI Tip 9738. How can I return the amount of physical memory, and the physical memory units, using built in functionality in Windows XP and Windows Server 2003?

In tip 7306, I described the SystemInfo.exe utility.

I have scripted PhysicalMemory.bat to return the amount of RAM, and the unit of measure.

The syntax for using PhysicalMemory.bat is:

PhysicalMemory Number Units

Where Number is a call directed numeric environment variable that will contain the amount of RAM, and Units is a call directed environment variable that will contain the units.

Example:

. . .
call PhysicalMemory Number Units
@echo %Number% %Units%
. . .
displays 1023 MB on my desktop computer.

PhysicalMemory.bat contains:

@echo off
if \{%2\}==\{\} @echo Syntax: PhysicalMemory Number Units&goto :EOF
for /f "tokens=4,5" %%a in ('systeminfo^|find "Total Physical Memory"') do (
 set %1=%%a
 set %2=%%b
)
call set /a %1=%%%1:,=%%



Hide comments

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.
Publish