2

I am trying to find out if an OS is 32 bit or 64 bit using a batch file and then running a program based on the output. Here is what I have so far

if (systeminfo | findstr = based) == "x64-based PC" run 64-bit Program
else run 32-bit program 

I keep getting "| is unexpected at this time". I have tried using a hat ^ and without parenthesis but I can't seem to get passed that error. Is there something I am missing or another way to do this. The batch file and programs will be on a flash drive and be used on multiple windows pc's. The systeminfo command is the only way I know of to get the bit result I need and I know that command works, but I need the program to look at the results and make a decision. Any thoughts would be greatly appreciated! Thanks in advance

Ravid Goldenberg
  • 2,119
  • 4
  • 39
  • 59

2 Answers2

6

Unfortunately, you cannot contain (possible) multi-line output systeminfo | findstr = based within an if statement.

You have to capture the output like this:

for /f "tokens=3" %%A in ('systeminfo ^| findstr based') do (
    if /i "%%~A"=="x64-based" (
        :: Run 64-bit Program
    ) else (
        :: Run 32-bit Program
    )
)

However, I would recommend just using the PROCESSOR_ARCHITECTURE.

reg query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR_ARCHITECTURE

https://stackoverflow.com/a/1739055/891976

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

Community
  • 1
  • 1
David Ruhmann
  • 11,064
  • 4
  • 37
  • 47
  • 3
    +1, It should also be noted that an `if` statement cannot contain a expression regardless of the number of commands and can only be specific text. – Patrick Meinecke Jun 27 '13 at 22:03
  • Thank You for your quick response. I will try the registry query as it does seem easier to use. – user2529815 Jun 27 '13 at 23:06
0

This is from a routine by @Aacini

if exist "%SYSTEMDRIVE%\Program Files (x86)" (
   echo Type=64 bit
) else (
   echo Type=32 bit
)
foxidrive
  • 40,353
  • 10
  • 53
  • 68