Is there a C++ .NET function that I can call that will detect if my program is running in compatibility mode? If there is not one, could someone show me the code for one? Thanks.
For example:
Program loads up Compatibility Mode check if true then exit else run
From another forum
After a few google searches went in vain, I decided to experiment myself. I found that the compatibility settings for each executable are stored - as I thought it would be - in the windows registry.
The key where the settings are stored is
HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\LayersFor each application that has its compatibility settings specified, there exists a value under that key whose name is the path to the executable and the data is a string consisting of the compatibility settings.
The keywords in the string that specify the compatibility settings are: WIN95 WIN98 NT4SP5
WIN2000 256COLOR 640X480
DISABLETHEMES DISABLECICEROIf multiple settings are specified (or are to be specified), the data consists of the settings above separated by a space each. The first four settings are mutually exclusive, i.e. only one of them is to be specified (if at all). I haven't tested the consequences of specifying multiple operating systems.
So, back to addressing your problem. To check if an executable (let's say, "C:\path\executable.exe") is set to run in 256 color mode, there would be a value named "C:\path\executable.exe" (without the quotes, even if the path contains spaces) under the key [HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers], and the data associated with the value would contain the string "256COLOR". If it is also set to run in compatibility mode under Windows 98/ME, the data would be "WIN98 256COLOR".
So, the approach is simple. Test if there is a value with the full path of the executable under the key I mentioned above. If there isn't, the executable has not been specified any compatibility settings. If the value exists, retrieve its data and check for the presence of "256COLOR" in the data. Accordingly, the presence of "WIN95" or "WIN98" or "NT4SP5" or "WIN2000" would mean that the executable is set to run in compatibility mode for that particular operating system.
Get the version of the operation system that is returned from GetVersionEx
and compare it to the file version on kernel32.dll
. When in application compatibility mode GetVersionEx
will always return the version of the operating system that is being 'emulated'. If both versions are different then you are in application compatibility mode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With