Is it possible to "declare" a windows cmd-file (batch-file) as 32 bit?

I have three possible solutions for your problem:

1) Use a wrapper batch file

In a company I used to work for, we had a single wrapper batch file for everything we ran. We did this to simplify interaction with our users, but it would work similarly. If you wanted, you could create a wrapper for each batch file (in essence, creating two batch files), or create a single wrapper that allows you to select each batch file from a menu (as described http://http-server.carleton.ca/~dmcfet/menu.html). You could have each menu selection identify the path to the batch file to run, and then you could have the wrapper choose the correct cmd.exe to launch it with.

2) Use the batch file as a self-wrapper

For each batch file, you could include a header which determines what OS you are on (32 or 64-bit). If you are on a 64-bit OS, you would know that, by default, you are launching it using the 64-bit version of cmd.exe. You could have that file then launch the 32-bit version of cmd.exe with the same batch file, but you could also pass the batch file a flag which tells it to ignore the 64-bit check. It would then run under the correct 32-bit cmd.exe.

For example:

@ECHO Off

::Check if 64-bit check skip flag exists

IF %1 == /skipcheck (goto run)

::Check if OS is 64-bit

IF %processor_architecture%==AMD64 (<path_to_32-bit_cmd> /c "<path_to_batch_file>\<name_of_my_batch_file>" /skipcheck)
IF %processor_architecture%==AMD64 (goto end)

:run

echo Hello World!

:end

I haven't tested the above code, so I might have some quotes or parenthesis in the wrong spot, but this is the general idea.

3) Migrate to PowerShell

PowerShell is available for all Windows OSes XP and newer. PowerShell is designed by Microsoft to eventually replace the simple cmd.exe, and provides a rich language for doing nearly any task. Most batch programs are actually runnable in PowerShell, and at most may require minimal tweaking.


You should explicitly run the cmd.exe version you want and have it execute your batch file:

For executing in 64-bit: C:\Windows\system32\cmd.exe /C path\to\batchfile.cmd
For executing in 32-bit: C:\Windows\SysWOW64\cmd.exe /C path\to\batchfile.cmd

The /C parameter executes the supplied command and terminates. (Yes, that's a link to XP documentation).


I am re-writing that wrapper to be more efficient and universal, just dump the header in and go, there is nothing to configure.

This will handle these scenarios not in the accepted answer:

  • Running on Systems without the "process architecture" variable (Older than XP) through Windows 10.
  • Running on x86 or x64 systems
  • The OS being Installed on drives and paths other than "C:\Windows"
  • Getting the script's Name and path to re-run itself automatically.
  • Passing all command line Arguments to the new iteration that is run.

Just dump the header in and go.

REM \/ HEADER TO ENSURE 32 Bit CLI \/
@(
    SETLOCAL
    ECHO OFF
    REM check for Only state where we are not in a 32 bit CMD
    ECHO."%PROCESSOR_ARCHITECTURE%_%ProgramFiles%" | FIND /I "AMD64_" | FIND /I /V "86"  >NUL && (
        CALL "%SystemRoot%\SysWOW64\cmd.exe" /c ""%~f0" %*"
        GOTO :EOF
    )
)
REM /\ HEADER TO ENSURE 32 Bit CLI /\

REM YOUR CODE HERE

(
   ENDLOCAL
   EXIT /b
)