Skip navigation

JSI Tip 3686. Batch script returns physical and available memory, number of processors, and OS version information


Using GetSysInfo.exe, I have scripted GetMPO.BAT, which returns the following environment variables:

Environment   
Variable
 
 D e s c r i p t i o n 
 jsipm   A character-based variable containing the number of bytes of physical memory. 
 jsipmk   An arithmetic variable that contains the number of kilobytes of physical memory. 
 jsiam   A character-based variable containing the number of bytes of available memory. 
 jsiamk   An arithmetic variable that contains the number of kilobytes of available memory. 
 jsinp   An arithmetic variable that contains the number of processors. 
 jsios   A quoted text string that contains the OS version. 

GETMPO.BAT contains:

@echo off
set /a cnt=0
for /f "Tokens=1,2 Delims=:" %%i in ('getsysinfo.exe') do call :parse "%%i" "%%j"
set param=
set cnt=
set len=
set char=
goto :EOF
:parse
set /a cnt=%cnt% + 1
if %cnt% GTR 7 goto :EOF
set param=%2
set param=%param:" ="%
goto parse%cnt%
:parse1
goto :EOF
:parse2
set jsinp=%param:"=%
set /a jsinp=%jsinp%
goto :EOF
:parse3
:parse4
goto :EOF
:parse5
set jsios=%param%
goto :EOF
:parse6
set param=%param:"=%#
set /a len=0
:parse6l
set /a len=%len% + 1
for /f %%n in ('@echo %%param:~%len%^,1%%') do set char=%%n
If "%char%" NEQ "#" goto parse6l
set jsipm=%param:#=%
set /a len=%len% - 3
for /f %%n in ('@echo %%jsipm:~0^,%len%%%') do set jsipmk=%%n
set /a jsipmk=%jsipmk%
goto :EOF
:parse7
set param=%param:"=%#
set /a len=0
:parse7l
set /a len=%len% + 1
for /f %%n in ('@echo %%param:~%len%^,1%%') do set char=%%n
If "%char%" NEQ "#" goto parse7l
set jsiam=%param:#=%
set /a len=%len% - 3
for /f %%n in ('@echo %%jsiam:~0^,%len%%%') do set jsiamk=%%n
set /a jsiamk=%jsiamk%



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