While recently designing an SCCM application, I ran into an issue where an EXE installer had to be executed in Windows 7 compatibility mode while running on Windows 10. Ironically the installed application itself ran fine in Win 10 without being in compatibility mode, but the installer wouldn’t. I needed to find a way to do this from the command line.
I learned that these compatibility entries are written in a straightforward fashion to the Windows Registry. It is actually the same location used to store application-level display and privilege level settings too (more on that in a moment). The registry key differs depending on if the setting applies to an individual user or to all users.
For an individual user: HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
For all users: HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers
Note that if settings are written to the HKLM (all users) location, users cannot change the affected settings in the file properties GUI unless they are an administrator.
For each item that has custom compatibility settings, a string is made. The name of the string is the path to the file and the data is specific to the desired compatibility setting(s):
There are three types of settings that can be applied to each application: compatibility mode, display settings, and privilege level. Modify the registry value to run the file as desired. If multiple settings are to be used, separate the data with a single space (like in the pskill.exe example pictured above: 256COLOR WIN95).
The following tables show the data values that I found:
|Windows Vista SP2||VISTASP2|
|Windows Vista SP1||VISTASP1|
|Windows XP SP3||WINXPSP3|
|Windows XP SP2||WINXPSP2|
|8-bit (256) Color Mode||256COLOR|
|16-bit (65536) Color Mode||16BITCOLOR|
|640 x 480 Screen Resolution||640X480|
|Disable Display Scaling on High DPI Settings||HIGHDPIAWARE|
|Run Program as Administrator||RUNASADMIN|
Therefore, it is possible to run a file in compatibility mode from command line…
…but it requires two commands be ran: one to create the appropriate registry value and another to run the file after the registry value has been made.
After learning this it was easy to create the following command that calls REG.EXE to create the registry value which forces my WorkstationInstaller.EXE file to run in Windows 7 compatibility mode:
REG ADD "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /V %cd%\WorkstationInstaller.exe /T REG_SZ /D WIN7RTM /F
I added this single command to my batch script right before I run WorkstationInstaller.EXE. Because this was for an SCCM application, I utilize the current directory environment variable %cd% to ensure it will always add the file location properly regardless of where the EXE exists in the CCM cache.