Solutions found in alt.msdos.batch

and alt.msdos.batch.nt

Display the amount of RAM installed

Windows NT 4/2000 only

 

Mike Castle posted the following interesting solution to display the amount of physical memory in NT.
It uses native NT commands only.

In article <9c94nn$n54$1@news.kolumbus.fi>,
Petri Paunonen <petri.paunonen@brandtgroup.fi> wrote:
>How could I dump the memsize of ram in simple form to a text file ?

@echo off
winmsd /s
for /f "tokens=2" %%v in ('findstr /r "^...Total:" %COMPUTERNAME%.txt') do set mem=%%v
del %COMPUTERNAME%.txt
for /f %%v in ('set /a %mem:,=% / 1024') do set mem=%%v
echo %mem%

-- 
       Mike Castle       Life is like a clock:  You can work constantly
  dalgoda@ix.netcom.com  and be right all the time, or not work at all
www.netcom.com/~dalgoda/ and be right at least twice a day.  -- mrc
    We are all of us living in the shadow of Manhattan.  -- Watchmen

Back to the top of this page . . .

 


 

GetRAM.bat

I have used this idea to create a batch file, GetRAM.bat, that displays the amount of RAM on the local NT 4 system:

@ECHO OFF
:: Enable command extensions and save initial environment
VERIFY OTHER 2>NUL
SETLOCAL ENABLEEXTENSIONS
IF ERRORLEVEL 1 (
	ECHO Unable to enable command extensions
	GOTO End
)

:: Check parameters
IF /I [%1]==[]   SET SWITCH=/V
IF /I [%1]==[/Q] SET SWITCH=/S
IF /I [%1]==[/S] SET SWITCH=/S
IF /I [%1]==[/V] SET SWITCH=/V
IF [%SWITCH%]==[] GOTO Syntax

:: Use WINMSD.EXE to check the amount of RAM installed
START /W WINMSD.EXE /S
:: Read the amount of RAM installed from WINMSD's report
FOR /F "tokens=2 delims=: " %%A IN ('TYPE %COMPUTERNAME%.TXT ^| FIND "Total:" ^| FIND /V "\"') DO SET RAM=%%A
:: Delete WINMSD's report
DEL %COMPUTERNAME%.TXT
:: Add 1023 to round up, or
:: add 512 for "mathematical" rounding, or
:: add 0 (or "rem out" next line) to round down
SET /A RAM = %RAM:,=% + 1023
SET /A RAM = %RAM:,=% / 1024
:: Use switch to determine display format
IF [%SWITCH%]==[/S] (
	ECHO %RAM%
) ELSE (
	ECHO.
	ECHO Total amount of RAM installed: %RAM% MB
)
GOTO End

:Syntax
ECHO.
ECHO GetRAM.bat, Version 1.10 for Windows NT
ECHO Displays the amount of RAM installed on this PC in MB
ECHO.
ECHO Idea: Mike Castle
ECHO Posted on alt.msdos.batch.nt, April 26, 2001
ECHO Extended by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO.
ECHO Usage:  %~n0  [ /Q ^| /S ^| /V ]
ECHO.
ECHO Switches:  /Q ^(quiet^) and /S ^(silent^) display the amount of RAM
ECHO                       installed on the computer as a number only
ECHO            /V ^(verbose^) also tells what it is displaying ^(default^)
ECHO.
ECHO This batch file uses NT's native WINMSD.EXE to check the amount of
ECHO RAM installed.
ECHO If you find it too slow and you have a copy of the Windows NT
ECHO Resource Kit you can use MEMORY.BAT instead.
ECHO MEMORY.BAT uses PSTAT.EXE to check the amount of RAM installed,
ECHO which is a lot faster.
ECHO MEMORY.BAT is available at http://www.robvanderwoude.com too.

:End
ENDLOCAL
 
Click to view source Click to download source
 

Back to the top of this page . . .

 


 

GetRAM2K.bat

This is the long awaited update for Windows 2000, GetRAM2K.bat:

@ECHO OFF
:: Enable command extensions and save initial environment
VERIFY OTHER 2>NUL
SETLOCAL ENABLEEXTENSIONS
IF ERRORLEVEL 1 (
	ECHO Unable to enable command extensions
	GOTO End
)

:: Check parameters
SET PC=%ComputerName%
ECHO.%1 | FIND "\\" >NUL
IF NOT ERRORLEVEL 1 (
	FOR /F "tokens=* delims=\" %%A IN ('ECHO.%~1') DO SET PC=%%A
	SHIFT
)
IF /I [%1]==[]   SET SWITCH=/V
IF /I [%1]==[/Q] SET SWITCH=/S
IF /I [%1]==[/S] SET SWITCH=/S
IF /I [%1]==[/V] SET SWITCH=/V
IF [%SWITCH%]==[] GOTO Syntax

:: Check Windows version
VER | FIND "Windows NT" >NUL
IF NOT ERRORLEVEL 1 GOTO NT4
VER | FIND "Windows 2000" >NUL
IF NOT ERRORLEVEL 1 GOTO W2K
GOTO Syntax

:NT4
:: Check if remote computer was specified by accident
IF DEFINED PC GOTO Syntax
:: Use WINMSD.EXE to check the amount of RAM installed
START /W WINMSD.EXE /S
:: Read the amount of RAM installed from WINMSD's report
FOR /F "tokens=2 delims=: " %%A IN ('TYPE %COMPUTERNAME%.TXT ˆ| FIND "Total:" ˆ| FIND /V "\"') DO SET RAM=%%A
:: Delete WINMSD's report
DEL %COMPUTERNAME%.TXT
:: Add 1023 to round up, or
:: add 512 for "mathematical" rounding, or
:: add 0 (or "rem out" next line) to round down
SET /A RAM = %RAM:,=% + 1023
SET /A RAM = %RAM:,=% / 1024
:: Use switch to determine display format
IF [%SWITCH%]==[/S] (
	ECHO %RAM%
) ELSE (
	ECHO.
	ECHO Total amount of RAM installed: %RAM% MB
)
GOTO End

:W2K
:: Delete old temporary file if it exists
IF EXIST "%Temp%.\%PC%.txt" DEL "%Temp%.\%PC%.txt"
:: Use WINMSD.EXE and MSINFO32.EXE to check the amount of RAM installed
START /W WINMSD.EXE /computer %PC% /categories +SystemSummary /report "%Temp%.\%PC%.txt"
:: Wait for the temporary report file to be generated -- though START /W did
:: wait for WINMSD.EXE to complete, WINMSD.EXE only started MSINFO32.EXE and
:: then terminated without waiting for MSINFO32.EXE to finish
:Wait
IF NOT EXIST "%Temp%.\%PC%.txt" (
	PING 1.1.1.1 -n 1 -w 5000 >NUL
	GOTO :Wait
)
:: Parse the relevant data from the temporary report file
:: Delims is a TAB followed by a SPACE
FOR /F "tokens=4,5 delims=	 " %%A IN ('TYPE "%Temp%.\%PC%.txt" ˆ| FIND /I "Total Physical memory"') DO (
	SET RAM=%%A
	SET Multiplier=%%B
)
:: Wait and retry if the file existed but was still being written
IF NOT DEFINED RAM GOTO :Wait
:: Parse the result and convert to MB
SET RAM=%RAM:,=%
SET RAM=%RAM:.=%
SET Div=1048576
SET Mup=1
SET Rnd=1048575
IF "%Multiplier%"=="KB" (
	SET Div=1024
	SET Rnd=1023
)
IF "%Multiplier%"=="MB" (
	SET Mup=1
	SET Div=1
	SET Rnd=
)
IF "%Multiplier%"=="GB" (
	SET Mup=1024
	SET Div=1
	SET Rnd=
)
SET /A RAM = %RAM% + %Rnd%
SET /A RAM = %RAM% * %Mup% / %Div%
:: Use switch to determine display format
IF [%SWITCH%]==[/S] (
	ECHO %RAM%
) ELSE (
	ECHO.
	ECHO Total amount of RAM installed on \\%PC%: %RAM% MB
)
GOTO End

:Syntax
ECHO.
ECHO GetRAM.bat, Version 2.00 for Windows NT 4 / 2000
ECHO Displays the amount of RAM in MB installed on this PC ˆ(or a remote PC, in
ECHO Windows 2000 only!ˆ)
ECHO.
ECHO Idea: Mike Castle
ECHO Posted on alt.msdos.batch.nt, April 26, 2001
ECHO Extended by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO.
ECHO Usage:  %~n0  [ \\remote_pc ]  [ /Q ˆ| /S ˆ| /V ]
ECHO.
ECHO Switches:  \\remote_pc           remote computer name ˆ(Windows 2000 only!ˆ)
ECHO            /Q          ˆ(quietˆ)   display the amount of RAM installed on the
ECHO                                  computer as a number only
ECHO            /S          ˆ(silentˆ)  same as /Q
ECHO            /V          ˆ(verboseˆ) also tells what it is displaying ˆ(defaultˆ)
ECHO.
ECHO This batch file uses NT's native WINMSD.EXE to check the amount of RAM
ECHO installed.
ECHO If you find it too slow and you have a copy of the Windows NT 4 Resource
ECHO Kit you can use MEMORY.BAT instead.
ECHO MEMORY.BAT uses PSTAT.EXE to check the amount of RAM installed, which is a
ECHO lot faster.
ECHO MEMORY.BAT is available at http://www.robvanderwoude.com too.

:End
ENDLOCAL & SET RAM=%RAM%
 
Click to view source Click to download source
 

Back to the top of this page . . .

 


 

Memory.bat

My own solution to the same question on alt.msdos.batch.nt was to use PSTAT.EXE from the NT Resource Kit)

FOR /F "tokens=2 delims=K " %%A IN ('PSTAT | FIND "Memory:"') DO SET MEM=%%A
:: The following command line determines the rounding method.
:: Add 0 to round down, 1023 to round up, or 512 for "mathematical" rounding.
SET /A MEM = %MEM% + 1023
SET /A MEM = %MEM% / 1024

The result was Memory.bat. It is much faster (PSTAT.EXE does not check hard disks, as WINMSD.EXE does), it does require the NT Resource Kit, whereas GetRAM.BAT uses native NT commands only.

@ECHO OFF
IF [%1]==[] GOTO Begin
ECHO.
ECHO Memory.bat, Version 1.01 for NT 4 with Resource Kit
ECHO Displays the amount of RAM installed on this PC in MB
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com
ECHO.
ECHO Use GETRAM.BAT instead if you do not have a copy of the Windows
ECHO NT Resource Kit available.
ECHO GETRAM.BAT is based on an idea posted on alt.msdos.batch.nt by
ECHO Mike Castle. It uses NT's native WINMSD.EXE instead of PSTAT.EXE
ECHO from the Resource Kit. However, it is much slower than this batch
ECHO file.
ECHO GETRAM.BAT is available at http://www.robvanderwoude.com too.
ECHO.
ECHO Total installed RAM in MB:

:Begin
:: Use PSTAT.EXE from the NT 4 Resource Kit
:: to find the amount of RAM installed (in KB)
FOR /F "tokens=2 delims=K " %%A IN ('PSTAT ^| FIND "Memory:"') DO SET RAM=%%A
:: The following command line is added to round up instead of down;
:: change the value from 1023 to 512 for "mathematical" rounding,
:: or remove the line to round down
SET /A RAM = %RAM% + 1023
:: Convert from KiloBytes to MegaBytes
SET /A RAM = %RAM% / 1024
:: Display the result
ECHO.%RAM%
 
Click to view source Click to download source
 

Back to the top of this page . . .


page last uploaded: 18 November 2011, 11:25