Four Ways to Effect Registry Changes at Logon
Exercising control over the performance and behavior of applications is of paramount concern in a Terminal Services environment. Often times, detail-oriented administrators seek to optimize the end-user's server-based environment by enforcing per-user settings in several different ways. Generally, in the case of 32-bit applications (and the Windows Explorer shell), these settings are stored in the user's registry hive, namely, HKEY_CURRENT_USER. Often times, to ensure a predictable and repeatable user experience, administrators effect such registry changes at logon using one of the automated mechanisms outlined below. Hundreds of well-known settings exist and are generally classified as either shell-specific (Explorer.exe) or application-specific (Office, Internet Explorer, PeopleSoft, etc). As an example, consider the following setting:
Sub-key: HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main
Value name: Force Offscreen Composition
Value data: 1
Value type: REG_DWORD
Purpose: When using Internet Explorer in a Terminal Services session to view a Web page that contains animated content, the animated content may flicker. Setting “Force Offscreen Composition” to 1 resolves the issue.
Below are four methods that you can exploit to write this value (or any other desirable value) to the user's registry at logon:
Method #1
1. Using REGEDIT, navigate to the aforementioned sub-key and export it to a file. Edit the file using Notepad and remove references to all other values that might have gotten exported in the process. The final file should look as follows:
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main]
"Force Offscreen Composition"=dword:00000001
Save the file with a .Reg extension in the %SystemRoot%\Application Compatibility Scripts\Logon directory (i.e., IESettings.Reg). Also, in the same directory, create a command script (i.e., IEUsr.Cmd) containing the following command:
REGEDIT –s IESettings.Reg
The –s switch instructs REGEDIT to “silently” import the registry file without prompting the user for confirmation. Finally, add the following statement to %SystemRoot%\System32\Usrlogn1.cmd:
Call IEUsr.Cmd
Interestingly, when a domain policy is in effect that prevents users from executing registry editing tools, you can re-associate the .Reg file type with Regedit.exe –s (as opposed to just Regedit.exe). In this case, the command script must call the registry file directly as follows, without any explicit references to REGEDIT:
Call IESettings.Reg
The file type re-association will cause the registry file to get imported silently.
Method #2
This method is similar to the above-described one, but makes use of REGINI as opposed to REGEDIT. To illustrate, create a text file called IESettings.Ini using Notepad. The file should look as follows:
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main
Force Offscreen Composition = REG_DWORD 1
Similarly to method #1, save the file under %SystemRoot%\Application Compatibility Scripts\Logon and create a command script (i.e., IEUsr.Cmd) containing the following command:
REGINI IESettings.Ini
Finally, add the following statement to %SystemRoot%\System32\Usrlogn1.cmd:
Call IEUsr.Cmd
Method #3
This method makes use of the Windows Script Host and VBScript to achieve the same goal. In the %SystemRoot%\Application Compatibility Scripts\Logon directory, simply create a text file called IEUsr.VBS as follows:
Dim oShell
Set oShell = CreateObject("Wscript.Shell")
oShell.RegWrite "HKCU\Software\Microsoft\Internet Explorer\Main\Force Offscreen Composition", 1, "REG_DWORD"
Finally, add the following statement to %SystemRoot%\System32\Usrlogn1.cmd:
Call IEUsr.Vbs
Method #4
This method makes use of a system policy (or Group Policy Objects). Simply copy the below text into Notepad and save the file with a .Adm extension to the %SystemRoot%\Inf directory (i.e., IESettings.Adm):
CLASS USER
CATEGORY !!TemplateDescription
KEYNAME "Software\Microsoft\Internet Explorer\Main"
POLICY !!DisableFlickering
VALUENAME "Force Offscreen Composition"
END POLICY
END CATEGORY
[Strings]
TemplateDescription="EOL's IE Optimization Settings"
DisableFlickering="Prevent IE Flickering under WTS"
Import this policy template using POLEDIT (NT 4.0 domain) or add it to the list of Administrative Templates under a new or existing Group Policy (Active Directory Domain). Finally, enable the “Force Offscreen Composition” setting.