Wednesday 25 March 2015

How to get operating system 32bit or 64bit from a Windows Batch File (BAT File)


I have recently been preparing some custom install scripts lately and I found a few things that may prove to be of some use! This script uses a registry key to determine weather the host system is a 32bit or a 64bit system

Code Snippet
  1. @echo off REM Hide output from commands
  2. @echo Attempting to get operating system type (32bit or 64bit)...
  3.  
  4. REM -------------- Get 32bit or 64bit --------------
  5. Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
  6. REG.exe Query %RegQry% > checkOS.txt
  7. Find /i "x86" < CheckOS.txt > StringCheck.txt
  8.  
  9. If %ERRORLEVEL% == 0 (
  10.     @echo This is 32 Bit Operating system!
  11.     SET ostype = "32bit"
  12. ) ELSE (
  13.     @echo This is 64 Bit Operating System!
  14.     SET ostype = "64bit"
  15. )
  16. del /s checkOS.txt >nul 2>&1 REM Clean up silently
  17. del /s StringCheck.txt >nul 2>&1 REM Clean up silently
End of Code Snippet

No comments: