Powered by GeSHi

Source code for getram.bat

(view source code of getram.bat as plain text)

  1. @ECHO OFF
  2. :: Enable command extensions and save initial environment
  3. VERIFY OTHER 2>NUL
  4. SETLOCAL ENABLEEXTENSIONS
  5. IF ERRORLEVEL 1 (
  6. 	ECHO Unable to enable command extensions
  7. 	GOTO End
  8. )
  9.  
  10. :: Check parameters
  11. IF /I [%1]==[]   SET SWITCH=/V
  12. IF /I [%1]==[/Q] SET SWITCH=/S
  13. IF /I [%1]==[/S] SET SWITCH=/S
  14. IF /I [%1]==[/V] SET SWITCH=/V
  15. IF [%SWITCH%]==[] GOTO Syntax
  16.  
  17. :: Use WINMSD.EXE to check the amount of RAM installed
  18. START /W WINMSD.EXE /S
  19. :: Read the amount of RAM installed from WINMSD's report
  20. FOR /F "tokens=2 delims=: " %%A IN ('TYPE %COMPUTERNAME%.TXT ^| FIND "Total:" ^| FIND /V "\"') DO SET RAM=%%A
  21. :: Delete WINMSD's report
  22. DEL %COMPUTERNAME%.TXT
  23. :: Add 1023 to round up, or
  24. :: add 512 for "mathematical" rounding, or
  25. :: add 0 (or "rem out" next line) to round down
  26. SET /A RAM = %RAM:,=% + 1023
  27. SET /A RAM = %RAM:,=% / 1024
  28. :: Use switch to determine display format
  29. IF [%SWITCH%]==[/S] (
  30. 	ECHO %RAM%
  31. ) ELSE (
  32. 	ECHO.
  33. 	ECHO Total amount of RAM installed: %RAM% MB
  34. )
  35. GOTO End
  36.  
  37. :Syntax
  38. ECHO.
  39. ECHO GetRAM.bat, Version 1.10 for Windows NT
  40. ECHO Displays the amount of RAM installed on this PC in MB
  41. ECHO.
  42. ECHO Idea: Mike Castle
  43. ECHO Posted on alt.msdos.batch.nt, April 26, 2001
  44. ECHO Extended by Rob van der Woude
  45. ECHO http://www.robvanderwoude.com
  46. ECHO.
  47. ECHO Usage:  %~n0  [ /Q ^| /S ^| /V ]
  48. ECHO.
  49. ECHO Switches:  /Q ^(quiet^) and /S ^(silent^) display the amount of RAM
  50. ECHO                       installed on the computer as a number only
  51. ECHO            /V ^(verbose^) also tells what it is displaying ^(default^)
  52. ECHO.
  53. ECHO This batch file uses NT's native WINMSD.EXE to check the amount of
  54. ECHO RAM installed.
  55. ECHO If you find it too slow and you have a copy of the Windows NT
  56. ECHO Resource Kit you can use MEMORY.BAT instead.
  57. ECHO MEMORY.BAT uses PSTAT.EXE to check the amount of RAM installed,
  58. ECHO which is a lot faster.
  59. ECHO MEMORY.BAT is available at http://www.robvanderwoude.com too.
  60.  
  61. :End
  62. ENDLOCAL
  63.