0

TL;DR : I need a piece of code that can identify the "bit" of windows and puts it in a variable called "bit", without any user input.

Currently, I am just using:

set /P choice=32 bit system? [Y/N]

    if /I "%choice%" EQU "Y" (
        :: 32 bit code
    ) else (
        :: 64 bit code
    )

But, I want something to identify if a user is using a 32/64 bit system no matter if they are running a 32/64 bit command prompt or the bit of there computer. In the post here there answer only states how to do it if you run the correct bit version of CMD.

Compo, a user on the site, helped me in the past with identifying what version of windows a user is running which reduced the number of user inputs a lot; however, I still haven't found a clean solution for the "bit" of windows.

CootMoon
  • 522
  • 4
  • 22
  • have you done a search before asking? [Batch to detect if system is a 32-bit or 64-bit](https://stackoverflow.com/q/4990839/995714), [Batch file to check os architecture and then execute appropriate exe](https://stackoverflow.com/q/22143039/995714), [If Processor=xx-bit do this in batch?](https://stackoverflow.com/q/42044600/995714) – phuclv May 17 '19 at 01:49

1 Answers1

4

How about:

if "%PROCESSOR_ARCHITECTURE%" EQU "x86" (
    rem 32 bit
) else (
    rem 64 bit
)

There's a slight complication if someone's running the 32 bit command prompt on a 64 bit system (where it will identify as 32 bit, even though the OS is 64 bit), but that can be fixed using:

if "%PROCESSOR_ARCHITECTURE%" EQU "x86" (
    if "%PROCESSOR_ARCHITEW6432%" EQU "AMD64" (
        rem 64 bit OS, but running a 32 bit command prompt
    ) else (
        rem 32 bit OS
    )
) else (
    rem 64 bit OS
)
Iridium
  • 23,323
  • 6
  • 52
  • 74