Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from Jan 17 '12 at 12:42

This question came from our site for professional and enthusiast programmers.

@CodyGray - Because I'm using an old compiler IDE (from Win95); changing to a new one would induce some costs we're not prepared for right now. If I build it and start it from the IDE, the whole thing crashes. If I put compability and start it from the explorer, it works. Which is good enough for me. Only I don't like putting compatibility flag every time after the build. Therefore the question ... :) – Rook Jan 13 '12 at 2:33
@CodyGray - Well, I could give you the whole story but I doubt it would fit in the commments box here (or three of them), so I'll just leave the question open for a while longer ... – Rook Jan 13 '12 at 9:11
Ah, I knew I remembered reading that in an article. I finally found it and posted an answer for posterity. :-) Feel free to ignore my nagging, but I seriously doubt you'll find an alternative approach. – Cody Gray Jan 13 '12 at 9:36

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.

share|improve this answer
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? – Rook Jan 17 '12 at 14:44
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. – Mike Brown Jan 22 '13 at 7:35

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|improve this answer

In a batch file use:


before the .exe call


share|improve this answer
+1 Starting an .exe through a .bat seems the least invasive solution – Wolf Nov 20 '14 at 10:25

Such a feature does not exist. That switch is intended for the user, not for the programmer!

If it were exposed in a way that a developer could switch it on automatically, that would remove their incentive to fix broken applications and make them compliant with newer versions of Windows, in turn forcing Microsoft to support badly broken applications forever.

The real solution is to fix the application so that it doesn't require compatibility shims to be applied in order to run. Remember that these compatibility switches restore broken behavior of previous Windows versions, and if your program relies upon them in order to work, that's evidence that it never should have worked in the first place because it was doing something that it should never have been doing. The fact that it ever worked on the original version of Windows is/was the bug, not the fact that it doesn't work on the current version of Windows.

To get started debugging the problem, take the advice from the linked blog article and use the Application Compatibility Toolkit to see all of the shims that are applied for whatever compatibility level your application requires, then apply them one at a time until you find the critical one. Once you've identified the culprit, go in and fix your code. Yes, I know it's not fun, but that's the price of maintenance programming (and, more accurately, not doing things right the first time). All of us on Stack Overflow are here to help if you run into problems trying to repair the brain-damaged code.

share|improve this answer
So, all versions previous to 7 were broken? I find that kind of thinking irrational. The irony in the whole story is that the compiler I'm using is also from Microsoft. In any case, I cannot "fix my code", the libraries used are from Microsoft's compiler which is no longer supported, and therefore the libraries also :/ – Rook Jan 13 '12 at 10:12
Yes, Microsoft isn't immune from bugs. They're constantly fixing them in Windows, and when applications rely on the previous buggy behavior that has now been removed, they stop working. Backwards compatibility is a huge industry, but it's intended for the convenience of users, not for programmers. Beyond that, there's a reason ancient compilers are no longer supported. Again, I don't know how you know exactly what the problem is without taking some time to debug it. It might not be nearly as difficult to fix as you think. Correctly written code can be migrated up to a newer compiler easily. – Cody Gray Jan 13 '12 at 10:15
Given the above answers, if nothing else, means "Such a feature does not exist" is factual incorrect. – user66001 Jul 23 '13 at 0:28
@user Going around the system and editing the registry is not a "feature" of the operating system. The app is broken. It needs to be fixed. I have no idea why this question was migrated to Super User. – Cody Gray Jul 23 '13 at 7:12
Disagree on both counts - Several sources seem to agree that compatibility mode is a "feature" of Windows (; Superuser is about computer software, that isn't about the programming of such ( Considering the OP's request of using the command line, and not done by a program, this seems right on topic to me. – user66001 Jul 23 '13 at 20:19

I don't buy the bit about older OS's being "broken" in all cases. It could also be the newer OSes that are broken due to a poorly considered fix. For example, in newer Windows versions (first noticed in Windows 8, but seen in Vista and 7 as well), USB Recording microphones using the built-in drivers get their gain levels dropped by 20dB for no apparent reason, in fact reducing the possible recorded dynamic range by that much. 20dB is more than 3 bits, not something to be tossed aside casually if audio quality is a concern (it is for me). Also, the gain sensitivity slider for USB Mic recording step sizes are different, making it difficult (maybe undefined? I can't find any documentation) for software to know what the actual setting is for compensations when this sensitivity value is important such as measurement applications. When using Windows XP, or the newer OSes with WinXPSP3 compat mode, things work as they should, 16 bit recording gives 16 bits of usable data and the gain setting tracks the setting in the mic's hardware chip exactly and goes to knowable levels.

share|improve this answer
Please read the question again carefully. Your answer does not answer the original question. – DavidPostill Mar 4 at 22:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .