57

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:

5YrsLaterDBA
  • 33,370
  • 43
  • 136
  • 210

23 Answers23

79

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
informatik01
  • 16,038
  • 10
  • 74
  • 104
Sam Spade
  • 807
  • 6
  • 2
  • 3
    This information was provided previously in [this answer](http://stackoverflow.com/a/19804271), but I like your implementation better because it doesn't use an intermediate file to hold the results. – Ken White Jul 05 '14 at 21:49
  • 3
    You've made a bug too - if should be `find /i "x86"`, there is no such thing as "x32" ) – mikalai Oct 24 '14 at 18:20
  • 7
    Also, you probably don't want to use OS as your environment variable because that's already set by Windows. 'OS=Windows_NT' on my machine – Adisak Dec 17 '14 at 22:47
  • 1
    It's what Android SDK tools uses. See https://android.googlesource.com/platform/sdk/+/master/find_java/find_java.bat#32 – Tim Kist Sep 28 '16 at 12:27
  • 2
    Put **`setlocal`** right after the `@echo off` line - this will ensure the lifetime of the environment will end with the termination of the batch, hence using the OS variable should not harm. – Matt Dec 09 '16 at 12:32
  • 1
    Really subtle: I would remove the space after the OS=32BIT assignment and before the or (||) because that space becomes part of the value of the %OS% variable. Important if you're going to do something like this later : if /i "%OS%" == "32bit" (echo is 32 bit) – john v kumpf Jan 10 '20 at 16:08
  • 1
    @TimKist It's funny that Android SDK file links back to this post. – alfoks Jul 03 '20 at 07:12
  • 1
    This will fail on 64bit sytsems, if any of the hex values begins with `0x86`. – Wiimm Nov 28 '20 at 17:13
  • On AMD Ryzen systems one of the values here has 0x86 as a value so this doesn't work on them. – CCarter Nov 22 '22 at 09:21
37

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.

Nic
  • 6,211
  • 10
  • 46
  • 69
Kerstin Fischer
  • 399
  • 1
  • 4
  • 7
  • 1
    This is good, but I prefer to use `IF DEFINED ProgramFiles(x86) ...` – paddy Nov 04 '13 at 22:52
  • 7
    Whoever invented batch if/else statements... I've never seen such a TERRIBLE interpreter. – Mgamerz Jun 19 '14 at 19:14
  • 3
    Isn't your test for `%PROCESSOR_ARCHITECTURE%` the wrong way around? I get `AMD64` on 64-bit. If `%PROCESSOR_ARCHITECTURE%` always works then it's a _much_ better solution than checking for a directory that any buggy piece of software can create regardless of CPU. – Rory Jun 23 '14 at 16:15
  • 3
    Spotted a bug - must exchange positive and negative branches in `IF "%PROCESSOR_ARCHITECTURE%"=="x86" (set bit=x64)`. – mikalai Oct 24 '14 at 18:11
  • 1
    @Mgamerz sure, it's far from ideal, but note that batch scripts can (and for sake of sanity, should) separate commands by lines, including within if/else blocks, as long as the opening bracket is on the same line as the condition, This makes things a lot more readable - within available limits! – underscore_d Aug 31 '15 at 19:12
21

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.

BendaThierry.com
  • 2,080
  • 1
  • 15
  • 17
  • 2
    @5YrsLaterDBA: If you have specific requirements you need to put them in your question. You have two correct answers to the question you actually asked. You should accept one and upvote both. – Carey Gregory Sep 07 '12 at 19:09
  • 2
    Beware: there is not enough to test only the `PROCESSOR_ARCHITECTURE` to find out the OS bitness. The example above tests only the script `cmd.exe` process bitness itself. To test the OS bitness like stated in the question you have additionally check existence of the `PROCESSOR_ARCHITEW6432` variable, because there is could be a 32-bit process on the 64-bit OS. – Andry Jan 12 '21 at 10:19
  • @Andry : At the time I have written these answer, 9 years before your answer, that script was useful. Things are subject to change less or more with time frames. Thanks for pointing that nowadays. – BendaThierry.com Feb 18 '21 at 10:59
  • @ThierryB It's not dependent to nowadays. The x64 OS and related variables nature left unchanged from the time it was appeared first time. The reason it was useful is you are half used it and not tested other cases. If you don't believe me then take the VM you want, install all Windows XP/7/8/etc versions with or w/o SP and take a look for yourself. – Andry Feb 18 '21 at 15:33
  • I will, but I have not used a Windows computer since ages, and I do not want to. Thanks for pointing that. It will certainly be useful for some people here. – BendaThierry.com Feb 18 '21 at 15:50
  • %PROCESSOR_ARCHITECTURE% will give x86 if the batch file is being run from a 32bit process. – CCarter Nov 22 '22 at 09:25
8

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
user66001
  • 774
  • 1
  • 13
  • 36
Emil Reña Enriquez
  • 2,929
  • 1
  • 29
  • 32
  • may I get a just reason on why this have 2 downvotes? I would like to know why this answer is not helpful – Emil Reña Enriquez Sep 14 '15 at 02:46
  • Venturing a guess at the reason for the downvotes is that the direction is to run the command from the command prompt, not instructions to put and then use the output of the command in a batch file, as the question asks for. – user66001 Jan 12 '17 at 17:30
  • 2
    I think the original question was expecting something that would work in a Batch file, e.g. `wmic os get osarchitecture | find "64" > NUL && set NumBits=64 || set NumBits=32` Otherwise, I think this is the most succinct answer... provided `wmic` is always present on the path.... – Steven the Easily Amused Mar 19 '18 at 01:34
5

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
BrickMan
  • 37
  • 8
S_R
  • 157
  • 1
  • 4
4
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
Steve-o
  • 12,678
  • 2
  • 41
  • 60
  • how to get those info in batch file with command-line commands? – 5YrsLaterDBA Sep 07 '12 at 17:05
  • 1
    @5YrsLaterDBA at least try researching the topic: http://www.computerhope.com/if.htm – Steve-o Sep 07 '12 at 17:07
  • A 64-bit OS can also mean IA64, by the way. – Joey Sep 07 '12 at 17:08
  • 1
    @Joey I'm pretending it doesn't exist like Oracle, la la la HP - I cannot hear you! – Steve-o Sep 07 '12 at 17:09
  • 1
    More useful info on this variable and how it acts on Win32/Win64/WOW64: http://blogs.msdn.com/b/david.wang/archive/2006/03/26/howto-detect-process-bitness.aspx – the_mandrill Nov 11 '13 at 09:43
  • 3
    This only detects the bitness of the command shell you are using, not of the OS itself. There are two versions of `cmd.exe` on 64-bit Windows, one is 64-bit and one is 32-bit (you can usually find it here: `C:\Windows\SysWOW64\cmd.exe`). – Igor Brejc Dec 20 '13 at 12:09
  • 64-bit Windows may also means Alpha or ARM beside Itanium. Unfortunate Windows for MIPS and PowerPC was dropped before they get 64-bit support – phuclv Mar 15 '18 at 16:33
  • Nothing simpler. Want to launch CCleaner.exe which is in the same fodler as your script ??? if %PROCESSOR_ARCHITECTURE%==x86 start %~dp0ccleaner.exe if %PROCESSOR_ARCHITECTURE%==AMD64 start %~dp0ccleaner64.exe – djibe Nov 02 '18 at 20:41
4
*** 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

Mahesh
  • 2,731
  • 2
  • 32
  • 31
4

'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
panako
  • 1,064
  • 10
  • 11
  • It works like a charm! Tested on Win7 and Vista (x86 and x64). Just keep in mind that if you need to handle WOW64, then also check PROCESSOR_ARCHITEW6432 (details - http://goo.gl/tWDK3V) – Alex Klaus Nov 28 '13 at 03:30
1

This is a one-liner that will have %errorlevel% of 0 for 64-bit, 1 for non-64-bit. I can't vouch for it working on all versions of Windows, but demonstrates one method for determining it. You can add multiple findstrqueries if you know all the possibilities to look for.

set | findstr /i processo.*64 > nul 2>&1

Basically, you're dumping the environment variables, and using a regular expression to search for something that has "processo" + "64" somewhere in its line. The piping is just to suppress the matching lines. If I changed it to set | findstr /i processo.*64 on my current rig, this would be the result:

 C:\Windows\System32>set | findstr /i processo.*64
PROCESSOR_ARCHITECTURE=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 158 Stepping 9, GenuineIntel

This is a one-liner to see if your processor is a 64-bit AMD

set | findstr /i processo.*amd.*64 > nul 2>&1

You can take these as a starting point and refine them for your requirements. I ended up using this over known environment variable names due to it being more reliable across different major versions of Windows that I was working with.

kayleeFrye_onDeck
  • 6,648
  • 5
  • 69
  • 80
  • 1
    I'm wary of depending on the environment. Double wary of expecting "AMD64" to be there in all cases, even if using an Intel processor. And triple wary that a user environment doesn't have something weird like `IWISH=I had a food processor as fast as amd graphics drivers like model 5564` – Steven the Easily Amused Mar 19 '18 at 01:31
  • You can add multiple `findstr` queries if you know what all you are looking for. I can't vouch for every version of 64-bit Windows having this environment variable. If you want to be as thorough as possible, you can look up the environment variables per-version of the Windows versions you're interested in, and have a query for each possible variable and value to eliminate your wariness. – kayleeFrye_onDeck Mar 20 '18 at 17:52
0

Here's my personal favorite, a logical bomb :)

::32/64Bit Switch
ECHO %PROCESSOR_ARCHITECTURE% | FINDSTR AMD64>NUL && SET ARCH=AMD64 || SET ARCH=x86
ECHO %ARCH%
PAUSE

With the AND's (&&) and OR's (||) this is a IF THEN ELSE Batch Construct.

zzeroo
  • 5,466
  • 4
  • 33
  • 49
  • For those who wondered why a straight if-else will not work; http://forums.codeguru.com/showthread.php?377124-RESOLVED-batch-IF-ELSE-STATEMENT One annoyance I've noticed is that assignments (i.e. SET statements) made within an IF block are not realized until AFTER the IF-bock. So, in other words, you can't rely on variable assignment within an IF-block. – AnneTheAgile May 29 '13 at 17:16
  • %PROCESSOR_ARCHITECTURE% returns x86 on a 64-bit machine if the process is running in 32-bit mode. e.g. if you run within `c:\windows\syswow64\cmd.exe` then it outputs x86. You can inspect `%PROCESSOR_ARCHITEW6432%` in this case which will be AMD64. – Rory Jun 23 '14 at 16:45
  • @AnneTheAgile I'm not sure your conclusion from that link is accurate; see http://stackoverflow.com/questions/7805510/dos-batch-file-set-variable-in-if-block for an example of other conditional pitfalls that might make someone _think_ that. Another possibly relevant thing is `setlocal enabledelayedexpansion` - which I use as a reflex anyway. – underscore_d Aug 31 '15 at 19:21
0

None of the answers here were working in my case (64 bit processor but 32 bit OS), so here's the solution which worked for me:

(set | find "ProgramFiles(x86)" > NUL) && (echo "%ProgramFiles(x86)%" | find "x86") > NUL && set bits=64 || set bits=32
teh_senaus
  • 1,394
  • 16
  • 25
0

I usually do the following:

:Check_Architecture
if /i "%processor_architecture%"=="x86" (
    IF NOT DEFINED PROCESSOR_ARCHITEW6432 (
        REM Run 32 bit command

    ) ELSE (
        REM Run 64 bit command
    )           
) else (
        REM Run 64 bit command
)
Adil Hindistan
  • 6,351
  • 4
  • 25
  • 28
0

Here's a nice concise version:

set isX64=False && if /I "%PROCESSOR_ARCHITECTURE%"=="AMD64" ( set isX64=True ) else ( if /I "%PROCESSOR_ARCHITEW6432%"=="AMD64" ( set isX64=True ) )

echo %isX64%

Don't use the "Program Files (x86)" directory as evidence of anything: naughty software can easily create this directory on a 32-bit machine. Instead use the PROCESSOR_ARCHITECTURE and PROCESSOR_ARCHITEW6432 environment variables.

Rory
  • 40,559
  • 52
  • 175
  • 261
0

I really do not understand some of the answers given here (sorry for that). The top-voted answer for example does not return the Windows architecture, instead it will give you the processor architecture. While running a 32-bits Windows build on a 64-bits CPU you will get the wrong result (it's a query on hardware being used).

The safest option is to query the BuildLabEx value from the registry.

Determine x86 (intel) or x86-64 (amd)

reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v "BuildLabEx" | >nul find /i ".x86fre."   && set "_ARCH_=x86" || set "_ARCH_=x86-64"

Determine x86 (intel), x86-64 (amd) or arm

set "_ARCH_=unknown"
reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v "BuildLabEx" | >nul find /i ".x86fre."   && set "_ARCH_=x86" 
reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v "BuildLabEx" | >nul find /i ".amd64fre." && set "_ARCH_=x86-64" 
reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v "BuildLabEx" | >nul find /i ".armfre."   && set "_ARCH_=arm" 

An alternative option (mentioned before)

if defined ProgramFiles(x86) ( set "_ARCH_=x86-64" ) else ( set "_ARCH_=x86" )

The problem with the latter is when you mess up your variables, you are not able to use this method. Checking for the folder's existence will cause problems too when there are leftovers from a previous install (or some user purposely created the folder).

FifthAxiom
  • 172
  • 1
  • 7
0

Problem with all the answers here is that they ignore whether your batch file is running under 32-bit or 64-bit cmd.exe which can happen on a 64-bit OS.

If that happens, then the filesystem redirection will kick in, and if you try to say copy a file to C:\Windows\System32 folder, it will end up in C:\Windows\SysWOW64 folder instead.

There is also registry redirection so you can do some really bad things if you don't test properly.

The following batch code should cover that:

@ECHO OFF
IF "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
    ECHO Running under 64-bit CMD.EXE on 64-bit Windows...
    REM C:\Windows\System32 is 64-bit here
) ELSE (
    IF "%PROCESSOR_ARCHITECTURE%"=="x86" IF "%PROCESSOR_ARCHITEW6432%"=="AMD64" (
        ECHO Running under 32-bit CMD.EXE on 64-bit Windows...
        REM C:\Windows\System32 is redirected to C:\Windows\SysWOW64 here
    ) ELSE (
        ECHO Running under 32-bit CMD.EXE on 32-bit Windows...
        REM C:\Windows\System32 is 32-bit here
    )
)

This is the only safe way to check from a batch file -- you should never assume that the user (or a 3rd party program) will run your batch from 64-bit cmd.exe on a 64-bit OS.

Igor Levicki
  • 1,017
  • 10
  • 17
-1

After much trial and error, I managed to get a few different working examples, but the kicker was when the batch was launched on a 64bit OS on a 32bit CMD. In the end this was the simplest check I could get to work, which works on Win2k-Win8 32/64. Also big thanks to Phil who helped me with this.

set bit64=n
if /I %Processor_Architecture%==AMD64 set bit64=y
if /I "%PROCESSOR_ARCHITEW6432%"=="AMD64" set bit64=y
MidLifeXis
  • 84
  • 5
Michael
  • 15
  • 1
-1

Many DOS commands in the different versions of Windows are similar but may support different parameters. Plus, newer versions of Windows may support new commands or retire older ones. Thus, if you wish to write a batch file that can run on different types of machines, it may prove beneficial to determine the version of Windows on which the batch file is running. This way the batch file can execute commands appropriate to the operating system.

The following batch file will determine whether or not the machine is running Windows 7, Windows Server 2008, Windows Vista, Windows Server 2003, Windows XP, Windows 2000, or Windows NT. It can easily be modified to support other versions of Windows as necessary or to set an environment variable based on the version of Windows detected. Note that for this batch file to correctly discern between newer versions of Windows Server and consumer versions of Windows, it is more convoluted than batch files you may see elsewhere. I have explained the reasoning below.

1) Open a Notepad window.

2) Copy the following text into Notepad (you may want to access this tip's printed version as some lines wrap):

@echo off

ver | find "2003" > nul
if %ERRORLEVEL% == 0 goto ver_2003

ver | find "XP" > nul
if %ERRORLEVEL% == 0 goto ver_xp

ver | find "2000" > nul
if %ERRORLEVEL% == 0 goto ver_2000

ver | find "NT" > nul
if %ERRORLEVEL% == 0 goto ver_nt

if not exist %SystemRoot%\system32\systeminfo.exe goto warnthenexit

systeminfo | find "OS Name" > %TEMP%\osname.txt
FOR /F "usebackq delims=: tokens=2" %%i IN (%TEMP%\osname.txt) DO set vers=%%i

echo %vers% | find "Windows 7" > nul
if %ERRORLEVEL% == 0 goto ver_7

echo %vers% | find "Windows Server 2008" > nul
if %ERRORLEVEL% == 0 goto ver_2008

echo %vers% | find "Windows Vista" > nul
if %ERRORLEVEL% == 0 goto ver_vista

goto warnthenexit

:ver_7
:Run Windows 7 specific commands here.
echo Windows 7
goto exit

:ver_2008
:Run Windows Server 2008 specific commands here.
echo Windows Server 2008
goto exit

:ver_vista
:Run Windows Vista specific commands here.
echo Windows Vista
goto exit

:ver_2003
:Run Windows Server 2003 specific commands here.
echo Windows Server 2003
goto exit

:ver_xp
:Run Windows XP specific commands here.
echo Windows XP
goto exit

:ver_2000
:Run Windows 2000 specific commands here.
echo Windows 2000
goto exit

:ver_nt
:Run Windows NT specific commands here.
echo Windows NT
goto exit

:warnthenexit
echo Machine undetermined.

:exit

3) Save the file as %WINDIR%\whichvers.bat

4) Now, from the command prompt, enter:

whichvers

This will display which version of Windows you are running.

NOTES:

  1. The reasoning for using the SYSTEMINFO command rather than relying on the VER command is because Windows Server 2008 "shares" version numbers with other Windows releases (see Microsoft). Thus relying on a "version number" of 6.0 to detect Windows Vista or 6.1 to detect Windows 7 fails to differentiate a machine from Windows Server 2008 or Windows Server 2008 R2.

  2. The creation of %TEMP%\osname.txt is solely because I could not place the results of systeminfo | find "OS Name" directly into the for /f command - it does not like piped commands. You may find an easier way to handle grabbing the information from SYSTEMINFO - if so, please comment.

  3. The environment variable %vers% has leading spaces. I could remove these with a longer batch file, but in this case it is not necessary.

  4. The batch file detects for SYSTEMINFO as it assumes if it gets beyond the older operating system detections, the running version of Windows is even older and will not have this utility. On Windows 7 64-bit it is still located in the %SystemRoot%\system32 folder - if later versions of Windows become 64-bit only, this batch file may have to be updated.

Return to the Windows XP and DOS page.

Dan Oberlam
  • 2,435
  • 9
  • 36
  • 54
-1

You can use the following registry location to check if computer is running 32 or 64 bit of Windows operating system:

HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0

You will see the following registry entries in the right pane:

Identifier     REG_SZ             x86 Family 6 Model 14 Stepping 12
Platform ID    REG_DWORD          0x00000020(32)

The above x86 and 0x00000020(32) indicate that the operating system version is 32 bit.

Sundeep
  • 23,246
  • 2
  • 28
  • 103
  • -1 Same answer (granted with slightly more detail) as [Sam spade's](http://stackoverflow.com/users/3808473) [answer](http://stackoverflow.com/questions/12322308/#24590583) over 2 years ago. – user66001 Jan 12 '17 at 17:37
-1
set bit=64
IF NOT DEFINED PROGRAMFILES(X86) (
set "PROGRAMFILES(X86)=%PROGRAMFILES%"
set bit=32
)
REM Example 1: REG IMPORT Install%bit%.reg (all compatibility)
REM Example 2: CD %PROGRAMFILES(X86)% (all compatibility)
-2
If $SYSTEM_os_arch==x86 ( 
  Echo OS is 32bit
 ) else ( 
  ECHO OS is 64bit
)
Sourabh Kumar Sharma
  • 2,864
  • 3
  • 25
  • 33
Ahze85283
  • 5
  • 1
-2

The correct way, as SAM write before is:

reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" /v "Identifier" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT

but with /v "Identifier" a little bit correct.

kgimpel
  • 594
  • 7
  • 8
  • This should be a comment on [Sam Spade's](http://stackoverflow.com/users/3808473) [post](http://stackoverflow.com/questions/12322308/#24590583), not adding another separate answer to the _many_ that are already cluttering this question. – user66001 Jan 12 '17 at 17:27
-2

FYI, try and move away from using %PROCESSOR_ARCHITECTURE% as SCCM made a change around version 2012 which always launces Packages/Programs under a 32-bit process (it can install x64 but environment variables will appear as x86). I now use;

IF EXIST "%SystemDrive%\Program Files (x86)" GOTO X64

Jack

  • Thanks for the note about the SCCM change (Have a link to the information handy?), but as other answer's have noted the existence of a directory that anyone/anything can create is risky. – user66001 Jan 12 '17 at 17:34
  • This won't work if OS language is set to anything other than English. – Igor Levicki Jan 08 '23 at 11:33
-3
set "_os=64"
if "%PROCESSOR_ARCHITECTURE%"=="x86" (if not defined PROCESSOR_ARCHITEW6432 set "_os=32")

Based on: https://blogs.msdn.microsoft.com/david.wang/2006/03/27/howto-detect-process-bitness/

and http://ss64.com/nt/syntax-64bit.html