JSI Tip 9535. How can a script return the number of processors, processor speed, physical memory, and other hardware and operating system values?

I introduced CompInfo.exe freeware to display the following information about your computer:

  • Number of Processors, Processor Type and Speed
  • Operating System and Service Pack Version
  • Physical and Virtual Memory plus Memory Load
  • Network Card, MAC Address, IP, DNS, Gateway and WINs Addresses
  • Logical Drive information including Volume Size, Serial Number, Label and Free Bytes
  • Video Card Type
  • Hard Disk and CDROM Information
  • Installed Printers
I have scripted PSR.bat as an example of how to set a variable based upon information returned by CompInfo.exe.

The syntax for using PSR.bat is:

call PSR numb speed memory

Where:

numb   is a call directed numeric environment variable that will contain the number of processors.

speed  is a call directed numeric environment variable that will contain the the CPU speed in mHz.

memory is a call directed numeric environment variable that will contain the amount of RAM in megabytes.
PSR.bat contains:
@echo off
if \{%3\}==\{\} @echo PSR numb speed memory&goto :EOF
setlocal ENABLEDELAYEDEXPANSION
set wrk="%TEMP%\info_%RANDOM%.TMP"
@echo Number of Processors Installed>%wrk%
@echo Processor 1 Speed>>%wrk%
@echo Installed Memory>>%wrk%
set /a numproc=0
set /a mhz=0
set /a ram=0
for /f "Tokens=1* Delims=:" %%a in ('compinfo^|findstr /i /g:%wrk%') do (
 set key=%%a
  for /f "Tokens=1" %%c in ('@echo %%b') do (
   if /i "!key:~1,4!" EQU "Numb" set /a numproc=%%c
   if /i "!key:~1,4!" EQU "Proc" set /a mhz=%%c
   if /i "!key:~1,4!" EQU "Inst" set /a ram=%%c   
 )
)
del /q %wrk%
endlocal&set /a %1=%numproc%&set /a %2=%mhz%&set /a %3=%ram%



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