Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does launching an app in Compatibility Mode in Windows affect the app and how can I detect it?

What does Windows do to an app when it is run in Compatibility Mode?

Is there a way I can detect the compatibility mode settings in .NET?

like image 357
Elmo Avatar asked Jan 11 '12 15:01

Elmo


1 Answers

What does Windows do to an app when it is run in Compatibility Mode?

It inserts several compatibility shims that mimic old behavior or bugs. Sometimes this is necessary, some programs behavior depends on old bugs which have since been fixed; or they used undocumented functionality.

Joel's blog entry, How Microsoft Lost the API War gives a nice example of that:

I first heard about this from one of the developers of the hit game SimCity, who told me that there was a critical bug in his application: it used memory right after freeing it, a major no-no that happened to work OK on DOS but would not work under Windows where memory that is freed is likely to be snatched up by another running application right away. The testers on the Windows team were going through various popular applications, testing them to make sure they worked OK, but SimCity kept crashing. They reported this to the Windows developers, who disassembled SimCity, stepped through it in a debugger, found the bug, and added special code that checked if SimCity was running, and if it did, ran the memory allocator in a special mode in which you could still use memory after freeing it.

That's what compatibility shims are meant to do. Insert legacy behavior. Whether it is to report a different version of Windows; make a certain API behavior a different way; or disable some other features of Windows that might cause problems like Aero.

The technical details of shims are here.

The Shim Infrastructure implements a form of application programming interface (API) hooking. Specifically, it leverages the nature of linking to redirect API calls from Windows itself to alternative code—the shim itself. The Windows Portable Executable (PE) and Common Object File Format (COFF) Specification includes several headers, and the data directories in this header provide a layer of indirection between the application and the linked file. Calls to external binary files take place through the Import Address Table (IAT).

Is there a way I can detect the compatibility mode settings in .NET?

The Question Is a Program Running in Compatibility Mode seems to give a relevant answer.

like image 158
vcsjones Avatar answered Oct 23 '22 05:10

vcsjones