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?

link|improve this question

63% accept rate
@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 ... :) – ldigas Jan 13 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 ... – ldigas Jan 13 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 at 9:36
feedback

migrated from stackoverflow.com Jan 17 at 12:42

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

2 Answers

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.

link|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? – ldigas Jan 17 at 14:44
feedback

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.

link|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 :/ – ldigas Jan 13 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 at 10:15
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.