[ TechHome ]

Applying Compatibility Layers

 Keywords: EnvironSet __COMPAT_LAYER Applying Compatibility Layer Mode AppCompatFlags


How to apply a compatibility fix through a WinBatch script. EnvironSet should be used to apply compatibility layers in WinBatch scripts:

The string you pass to EnvironSet should be formatted as

__COMPAT_LAYER=[!]layer_name1 [layer_name2 ...]
Where __COMPAT_LAYER is the name of the envronment variable and Layer_name is the short name of the compatibility layer being applied.
EnvironSet('__COMPAT_LAYER','!WinXP')
NOTE: COMPAT_LAYER is proceeded by two underscores (_). The command does not work without both underscores.

The exclamation point indicates that the Layers should not be added to existing compatibility fixes in the database files.

NOTE: Compatibility layer names must be separated by a space.

For example:

EnvironSet('__COMPAT_LAYER','!Win95 DisableThemes')
To disable the compatibility layer after it has been applied in this fashion, use the same command without specifying a compatibility layer.

For example:

EnvironSet('__COMPAT_LAYER','')
When you apply compatibility layers in this way, you also ensure that the compatibility layer is passed on recursively to any other process that might be spawned by the commands in the WinBatch script . Any processes that were started while the compatibility layer was in effect will still run under the compatibility layer until they are terminated.

Each of the most common compatibility layers has a short version of its name that can be used with the set __COMPAT_LAYER command in a script.

The list of available compatibility layers includes the following short name and its full name:

Code Sample:
appname = 'notepad.exe'
EnvironSet( '__COMPAT_LAYER', '!WinXP')
RunEnviron( appname, '', @NORMAL, @NOWAIT)
EnvironSet('__COMPAT_LAYER','')


MORE

http://www.verboon.info/index.php/2011/03/running-an-application-as-administrator-or-in-compatibility-mode/

Apparently compatibility settings for each executable are stored in the windows registry.The key where the settings are stored is

HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

For 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: Compatibility Modes

WIN95 - Windows 95
WIN98 - Windows 98
WIN4SP5 - Windows NT 4.0 SP5
WIN2000 - Windows 2000
WINXPSP2 - Windows XP SP2
WINXPSP3 - Windows XP SP3
VISTARTM - Vista
VISTASP1 - Vista SP1
VISTASP2 - Vista SP2
WIN7RTM - Windows 7 
WINSRV03SP1 - Windows Server 2003 SP1
WINSRV08SP1 - Windows Server 2008 SP1
Display Settings
DISABLETHEMES - Disable Visual Themes
640X480 - Run in 640 x 480 screen resolution
HIGHDPIAWARE - Disable display scaling on high DPI settings
256COLOR - Run in 256 colors
DISABLEDWM - Disable Desktop Composition
Privilege Level
RUNASADMIN - Run program as an administrator
If multiple settings are specified, the data consists of the settings above separated by a space. The first four settings are mutually exclusive. 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.
Article ID:   W17914
Filename:   Control Compatibility Mode.txt
File Created: 2012:04:23:08:15:24
Last Updated: 2012:04:23:08:15:24