batch file to check 64bit or 32bit OS
Can I check to see if current machine is running 64bit OS or 32bit OS inside a batch file?
EDIT:
Found this online and it is good enough to me now:
Solution 1:
This is the correct way to perform the check as-per Microsoft's knowledgebase reference ( http://support.microsoft.com/kb/556009 ) that I have re-edited into just a single line of code.
It doesn't rely on any environment variables or folder names and instead checks directly in the registry.
As shown in a full batch file below it sets an environment variable OS equal to either 32BIT or 64BIT that you can use as desired.
@echo OFF
reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT
if %OS%==32BIT echo This is a 32bit operating system
if %OS%==64BIT echo This is a 64bit operating system
Solution 2:
I use either of the following:
:CheckOS
IF EXIST "%PROGRAMFILES(X86)%" (GOTO 64BIT) ELSE (GOTO 32BIT)
:64BIT
echo 64-bit...
GOTO END
:32BIT
echo 32-bit...
GOTO END
:END
or I set the bit
variable, which I later use in my script to run the correct setup.
:CheckOS
IF EXIST "%PROGRAMFILES(X86)%" (set bit=x64) ELSE (set bit=x86)
or...
:CheckOS
IF "%PROCESSOR_ARCHITECTURE%"=="x86" (set bit=x86) else (set bit=x64)
Hope this helps.
Solution 3:
Seems to work if you do only these:
echo "%PROCESSOR_ARCHITECTURE%"
I've found these script which will do specific stuff depending of OS Architecture (x64 or x86):
@echo off
echo Detecting OS processor type
if "%PROCESSOR_ARCHITECTURE%"=="AMD64" goto 64BIT
echo 32-bit OS
\\savdaldpm01\ProtectionAgents\RA\3.0.7558.0\i386\DPMAgentInstaller_x86 /q
goto END
:64BIT
echo 64-bit OS
\\savdaldpm01\ProtectionAgents\RA\3.0.7558.0\amd64\DPMAgentInstaller_x64 /q
:END
"C:\Program Files\Microsoft Data Protection Manager\DPM\bin\setdpmserver.exe" -dpmservername sa
Try to find a way without GOTO please...
For people whom work with Unix systems, uname -m
will do the trick.
Solution 4:
Run the below in the command prompt:
Start -> Run -> Type cmd
and enter the command below in the resulting black box:
wmic os get osarchitecture