Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch to detect if system is a 32-bit or 64-bit

Does anybody know how to create a batch file that can shell one program if its a 64-bit system or shell another if its a 32-bit system?

like image 249
philip Avatar asked Feb 14 '11 10:02

philip


People also ask

Is CMD 32 or 64-bit?

There is both a 32bit and 64bit version of the command processor (cmd.exe) and the same applies to some of the other core system components, such as the registry editor (regedit.exe). Which one you use depends on how you start the command processor.


2 Answers

Check for %PROCESSOR_ARCHITECTURE% being x86:

if %PROCESSOR_ARCHITECTURE%==x86 (
  rem 32 bit
) else (
  rem 64 bit
)

At least for the time being. On a server I have access to it's AMD64 but no clue how Itanium looks like, for example. But 32-bit versions always report x86.

Another option, that also works on WoW64:

for /f "skip=1 delims=" %%x in ('wmic cpu get addresswidth') do if not defined AddressWidth set AddressWidth=%%x

if %AddressWidth%==64 (
  rem 64 bit
) else (
  rem 32 bit
)
like image 124
Joey Avatar answered Oct 02 '22 12:10

Joey


It works without WMI too! I suggest:

 @echo off
 if /i "%processor_architecture%"=="AMD64" GOTO AMD64
 if /i "%PROCESSOR_ARCHITEW6432%"=="AMD64" GOTO AMD64
 if /i "%processor_architecture%"=="x86" GOTO x86
 GOTO ERR
 :AMD64
    rem do amd64 stuff
 GOTO EXEC
 :x86
    rem do x86 stuff
 GOTO EXEC
 :EXEC
    rem do arch independent stuff
 GOTO END
 :ERR
 @echo Unsupported architecture "%processor_architecture%"!
 pause
 :END
like image 22
Josef says Reinstate Monica Avatar answered Oct 02 '22 11:10

Josef says Reinstate Monica