How can I set the compatibility mode for an executable from the command line?

Is there a way to set the compatibility with XP option (right click/properties/compatibility ... that one, yes :) to an executable from the command line?

Or better yet, is there a way to set compatibility to a whole directory (executables in the directory), so that every executable that gets compiled/build already has that "flag" on it?


Solution 1:

I don't know a tools that allows to set or change the application compatibility flags.

However the application compatibily flags are stored in the registry (user or system part):

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

Therefore you can use the standard command line registry editor for creating the required entry:

reg.exe Add "HKLM\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "C:\Program Files\MyApp\Test.exe" /d "WINXPSP3"

For more details on the available flags see the blog post Running an Application as Administrator or in Compatibility Mode.

Solution 2:

In a batch file use:

> set __COMPAT_LAYER=WinXP

before the .exe call

See:

  • WWW Tech Support/winbatch/How To\Control Compatibility Mode.txt

  • HOW TO: Script Compatibility Layers in Windows XP

Solution 3:

Robert's answer was spot-on. To expand on it a bit, and answer the OP's question about setting the mode en masse...

If you have a folder full of .exe files to process, you can do this:

for %x in ("*.exe") do reg.exe Add "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "%~fx" /d "WINXPSP3"

This example uses HKCU instead of HKLM; be sure to pick the one you really want.

To remove the settings, with a confirmation prompt for each one:

for %x in ("*.exe") do reg.exe Delete "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "%~fx"

Add /f to the end if you don't want to be prompted for confirmation.

(If you vote this answer up, please vote up Robert's as well!)