Recently we had a problem with very slow logons to one of the Terminal Servers. The terminal server is currently running Windows 2003 Server, but I would bet it could be the same problem on 2008 or even Windows Server 2012.

The problem is with printer caching, usually bloated drivers that get cached when a user logons. HP is famous for having bloated drivers, but Sharp is pretty bad too. We use mostly Sharp copiers across our facility, many, many copiers and lots of Brother printers.  Basically it is a few minute quick fix to get your server working again and then we will automate the process so you can set it and forget it. All we will be doing is deleting a couple of registry keys, so no need to worry, this doesn’t affect drivers or anything, these keys are automatically recreated. Just check these keys and see if you have hundreds or even thousands of entries, if so, you can manually delete the key and your server will return to its lightning fast self. It’s easier and faster to use the script below though.

NOTE: Be patient, the first time we did this it took between 20 and 30 minutes to delete just one key. Also, you will notice if people are currently logging in or logged on that not all entries will be removed, that’s completely fine.

HKEY_CURRENT_USER\Software\SHARP HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\SHARP
HKEY_USERS\.DEFAULT\Software\SHARP

If you have HP copiers, then you will see these keys instead.

HKEY_CURRENT_USER\Software\Hewlett-Packard HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install Software\Hewlett-Packard
HKEY_USERS\.DEFAULT\Software\Hewlett-Packard
 

This is a temporary fix, I highly recommend creating the cleanup scripts below to make it a permanent solution. I will attach mine to this article, feel free to download and use them, at your own risk of course, but you will notice they are basic one or two line scripts that simply remove some registry keys. If you are worried just backup the key first.

You will need two scripts, one to call a registry deletion of HKLM and HKU, and the other will call the key deletion of HKCU. We put our scripts in the system32 folder so if you put your script else where, just update the location in the script. This is all really basic stuff so I’m not going to go into too many details.

First, Logon as an Admin user and follow the steps below:

Create script in C:\Windows\system32\ called “CleanupSharp.bat” with this code in it:

regedit /s C:\Windows\system32\CleanupSharp.reg

Create a reg file in C:\Windows\system32\ named “CleanupSharp.reg” with this text in it:

Windows Registry Editor Version 5.00
[-HKEY_USERS\.DEFAULT\Software\SHARP]
[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\SHARP]

At this point, simply run the CleanupSharp.bat script to get your Terminal Server responding normally again. Then move on to the steps below to make it as fast as it can be. This cleans the user hives, which helps a lot, but not nearly as much as the first script, it is very important though so don’t skip this step lazy ass.

Create script in C:\Windows\system32\ called “CleanupSharp-user.bat” with this code in it:

regedit /s C:\Windows\system32\CleanupSharp-user.reg

Create a reg file in C:\Windows\system32\ named “CleanupSharp-user.reg” with this text in it:

Windows Registry Editor Version 5.00
[-HKEY_CURRENT_USER\Software\SHARP]

 

Now, Let’s automate the process… see below for a zip file with scripts.

Run or open gpedit.msc and go to Computer Configuration->Windows Settings->Scripts and add “C:\Windows\system32\CleanupSharp.bat” to shutdown scripts.

Then go to User Configuration-> Windows Settings-> Scripts and add the other script C:\Windows\system32\CleanupSharp-user.bat to logoff scripts.

Logon as a regular user and that should remove the SHARP current user key on logoff, make sure you logoff then back on to the machine to verify ;-)

If for some reason nobody is logged on to your Terminal Server you can do a reboot and test the shutdown script removes the other keys.

That’s all there is to it! If you use HP, be sure to change the “SHARP” to “Hewlett-Packard”. If you have other copiers or printers, just check them, if there is a ton of lines in the key, then substitute that name in the reg files.

Now enjoy your like new Microsoft Terminal Server :)

Here is the link to the files TS_Printer_Clean