Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 stackoverflow.com 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 ... :) –  ldigas 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 ... –  ldigas 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
add comment

4 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.

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? –  ldigas 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
add comment

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
1  
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 '12 at 10:12
1  
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
1  
Given the above answers, if nothing else, means "Such a feature does not exist" is factual incorrect. –  user66001 Jul 23 '13 at 0:28
1  
@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
1  
Disagree on both counts - Several sources seem to agree that compatibility mode is a "feature" of Windows (nextofwindows.com/how-to-use-compatibility-mode-in-windows-7); Superuser is about computer software, that isn't about the programming of such (superuser.com/help/on-topic). 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
show 8 more comments

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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