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

97,161

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:

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!)

Share:
97,161

Related videos on Youtube

Rook
Author by

Rook

Updated on September 18, 2022

Comments

  • Rook
    Rook almost 2 years

    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?

  • Rook
    Rook over 12 years
    Hmm, this just might(!) work ... that third line "reg.exe ..." ... so if I set it for every exe I have in some directory, it will "stay attached" to that executable even if it is rebuild?
  • Mike Brown
    Mike Brown over 11 years
    The normal behavior of right-click > Properties > Compatibility is to set the keys under HKCU, unless the "Change settings for all users" button is pressed. Then it is set under HKLM for all users, and can't be changed via the dialog.