Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

batch file to check 64bit or 32bit OS

People also ask

How can I tell if my OS is 32 or 64-bit command line?

Press [Windows] key + [R] to open the “Run” dialog box. Enter cmd and click [OK] to open Windows Command Prompt. Type systeminfo in the command line and hit [Enter] to execute the command.

How do I run a 32-bit batch file on 64-bit?

Next you need to call every console application in System32 directory of Windows with %SystemPath% in your batch file, for example %SystemPath%\findstr.exe . Of course you could also start cmd with %SystemPath%\cmd.exe to run always 64-bit command line interpreter from within the batch file.


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

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.


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.


*** Start ***

@echo off

Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0

REG.exe Query %RegQry% > checkOS.txt

Find /i "x86" < CheckOS.txt > StringCheck.txt

If %ERRORLEVEL% == 0 (
    Echo "This is 32 Bit Operating system"
) ELSE (
    Echo "This is 64 Bit Operating System"
)

*** End ***

reference http://support.microsoft.com/kb/556009


'ProgramFiles(x86)' is an environment variable automatically defined by cmd.exe (both 32-bit and 64-bit versions) on Windows 64-bit machines only, so try this:

@ECHO OFF

echo Check operating system ...
if defined PROGRAMFILES(X86) (
    echo 64-bit sytem detected
) else (
    echo 32-bit sytem detected
)
pause

If you are running the script as an administrator, then the script can use the wmic command.

FOR /f "tokens=2 delims==" %%f IN ('wmic os get osarchitecture /value ^| find "="') DO SET "OS_ARCH=%%f"
IF "%OS_ARCH%"=="32-bit" GOTO :32bit
IF "%OS_ARCH%"=="64-bit" GOTO :64bit

ECHO OS Architecture %OS_ARCH% is not supported!
EXIT 1

:32bit
ECHO "32 bit Operating System"
GOTO :SUCCESS

:64bit
ECHO "64 bit Operating System"
GOTO :SUCCESS

:SUCCESS
EXIT 0

PROCESSOR_ARCHITECTURE=x86

Will appear on Win32, and

PROCESSOR_ARCHITECTURE=AMD64

will appear for Win64.

If you are perversely running the 32-bit cmd.exe process then Windows presents two environment variables:

PROCESSOR_ARCHITECTURE=x86
PROCESSOR_ARCHITEW6432=AMD64