Scripting Compatibility Layers
What do you do if you have
a batch file that needs to run one or more programs within a temporary
compatibility layer? You can handle this by using the following command
within the batch file before you start the program:
SET __COMPAT_LAYER=[!]layer1 [layer2 ...]
Here, layer1 and layer2 are codes that represent the compatibility layers. Table 1 lists the 11 codes you can use.
Table 1. Codes to Use When Scripting Compatibility Layers
Code | Compatibility Layer |
---|
Win95 | Windows 95. |
Win98 | Windows 98 / Windows Me. |
Win2000 | Windows 2000. |
NTSP5 | Windows NT 4.0 SP 5. |
256Color | 256 color. |
640x480 | 640×480 screen resolution. |
DisableThemes | Disable visual themes. |
International | This layer handles incompatibilities caused by double-byte character sets. |
LUA | Limited User Access—This
layer redirects some Registry and file operations to nonrestricted
areas for users that don’t have permission to access restricted areas
(such as the HKLM key). |
LUACleanup | Limited User Access Cleanup—This layer removes the Registry settings and files that were redirected using the LUA layer. |
ProfilesSetup | Profile
Setup Support—This layer is used for older programs that install only
for the current user; the layer ensures that the program is installed
for all users. |
If
you’ve already applied one or more layers to the program using the
techniques from the previous section, you can tell Windows XP not to use
one of those layers by preceding its keyword with the ! symbol. Also, to turn off the compatibility layers, run the command without any parameters, like so:
For example, the
following commands set the compatibility layers to Windows 95 and 256
colors, run a program, and then remove the layers:
SET __COMPAT_LAYER=Win95 256Color
D:\Legacy\oldapp.exe
SET __COMPAT_LAYER=
Note
The compatibility layers created by SET __COMPAT_LAYER also apply to any processes that are spawned by the affected application. For example, if you set the Windows 95 layer for Setup.exe, the same layer will also apply to any other executable called by Setup.exe.
Using Application Compatibility Toolkit
When you execute a
program using a compatibility layer, Windows XP creates an environment
within which the program can function properly. For example, a program
running under the Win95 layer actually believes that Windows 95 is the operating system. Windows XP accomplishes that not only by returning the Windows 95 version number when the program calls the GetVersion or GetVersionEx
API functions, but also by “fixing” other incompatibilities between
Windows 95 and Windows XP. For example, Windows 95 programs expect
components such as Calculator and Solitaire to be in the %SystemRoot% folder, but in Windows XP these are in the %SystemRoot%\System32\ folder. The Win95 layer intercepts such file calls and reroutes them to the appropriate location.
The Win95 layer
comprises more than 50 such fixes, which are part of a large database of
incompatibilities maintained by Microsoft. As of this writing, far more
than 200 incompatibilities have been identified, and others might be
found in the future. To get access to all these fixes and so get
fine-tuned control over the compatibility issues relating to any legacy
program, you need to use Application Compatibility Toolkit (ACT).
To install ACT, you have two choices:
The ACT package comprises a
number of programs and tools. Some of these are for programmers only,
so the next two sections look at the main end-user tool: Compatibility
Administrator.
Using Compatibility Administrator
To create a usable
compatibility fix for an application—one that you can use on your own
computer or distribute to other computers—you use Compatibility
Administrator. Compatibility Administrator stores fixes in databases:
System database | This
database contains three items: a list of applications for which
Microsoft has applied fixes for known problems, a list of the available
compatibility fixes, and the defined compatibility modes (that is, the
compatibility layers discussed earlier). |
Installed databases | These are databases that have been installed on this computer. |
Custom databases | These are databases that contain fixes that you applied to one or more applications. |
There are two ways to start this program:
If
you’re using the original version of ACT, select Start, All Programs,
Application Compatibility Toolkit, Compatibility Administration Tool.
If
you’re using the latest version of ACT, select Start, All Programs,
Microsoft Application Compatibility Toolkit, Tools, Compatibility
Administrator.
Here’s
how to create a custom fix database (note that I’m using version 4.0 of
Compatibility Administrator for these instructions):
1. | A
new database is created for you automatically under the Custom
Databases branch. Either select this database or create a new one by
clicking Custom Database and then selecting File, New.
|
2. | Right-click the new database, click Rename, and then enter a name for the database.
|
3. | To create a new application fix, click the Fix button in the toolbar to launch the Create New Application Fix Wizard.
|
4. | Enter the program’s name, vendor, and location, and then click Next. The Compatibility Modes dialog box appears.
|
5. | Choose
an operating system mode and use the check boxes in the Select
Additional Compatibility Modes list to choose additional layers to apply
to the program, as shown in Figure 1. Click Next. The Compatibility Fixes dialog box appears.
|
6. | Use the check boxes to apply specific compatibility fixes and then click Next.
|
7. | Compatibility
Administrator also needs to know how to identify the program. Click
Auto-Generate to have the wizard set up the matching attributes for you,
and then click Finish.
|
Compatibility Administrator
adds your program to the database. To try out the program, click it and
click Run. Then select View, View Log to see the log that Compatibility
Administrator created. Use the log to determine which fixes were
required by the program. Then edit the fix to deactivate any fixes that
aren’t required by the program. To change the fixes, right-click the
program’s executable filename in the right pane and then click Edit
Application Fix.
After you’ve added all
the fixes for all your incompatible programs to the database, save the
database file. To enable Windows XP to use the resulting .sdb
file, you need to install the file by highlighting it and selecting
File, Install. To distribute the fix to another computer, copy the .sdb file to the machine, launch Compatibility Administrator, and then click Open to open the .sdb file. You can then install the database.