Howtos / Articles

Force .Net Application to run as 32 bit

If you have a .Net application that has been compiled with the target CPU option set to AnyCPU (as opposed to x86 / 32bit or x64 / 64bit specifically) and you are running a 64bit operating system, that application will automatically run as a 64bit process. If you run it on a 32bit machine, it will run in a 32bit mode.

You can however change the CorFlags of the executable, to force it to run as a 32bit process, even if you are running a 64bit operating system. This process changes the headers of the .Net portable executable file.

The CorFlags.exe tool that gets installed with Visual Studio can be used to change the CorFlags.

Change the CorFlags

Open a “Visual Studio Command Prompt” or “Developer Command Prompt” depending on your version of Visual Studio.
(this simply puts the path that contains corflags info the search path %PATH%, so you don’t need to be in the specific folder containing corflags.exe)

Run the following command:

CorFlags.exe yourapplication.exe /32BIT+

or depending on your version of Visual Studio, you may need to use the following command:

CorFlags.exe yourapplication.exe /32BITREQ+

Replace ‘yourapplication.exe’ with the .Net application that you want to change the corflags on.

To view all the commands supported by your version of CorFlags.exe, simply run CorFlags.exe with no parameters.

Eg:

C:\Program Files (x86)\Microsoft Visual Studio 14.0>corflags.exe
Microsoft (R) .NET Framework CorFlags Conversion Tool.  Version  4.6.1055.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Usage: Corflags.exe Assembly [options]

If no options are specified, the flags for the given image are displayed.

Options:
/ILONLY+ /ILONLY-       Sets/clears the ILONLY flag
/32BITREQ+ /32BITREQ-   Sets/clears the bits indicating 32-bit x86 only
/32BITPREF+ /32BITPREF- Sets/clears the bits indicating 32-bit preferred
/UpgradeCLRHeader       Upgrade the CLR Header to version 2.5
/RevertCLRHeader        Revert the CLR Header to version 2.0
/Force                  Force an assembly update even if the image is
                        strong name signed.
                        WARNING: Updating a strong name signed assembly
                         will require the assembly to be resigned before
                         it will execute properly.
/nologo                 Prevents corflags from displaying logo

Additional Info

For more info on Corflags, check the Microsoft website.
https://docs.microsoft.com/en-us/dotnet/framework/tools/corflags-exe-corflags-conversion-tool



Share this howto article!
  • Facebook
  • Twitter
  • Reddit
  • email

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>