If you administer Terminal Services or Citrix MetaFrame, you know that locally cached user profiles can cause a mess on your server’s hard drive by chewing up valuable space. You must remove these profiles often in order to prevent them from filling up your server’s hard drive.

The easiest way to delete these files is by using Explorer. However, the easiest way isn’t always the best. Using Explorer for this cleanup job can actually create a host of new problems. In this case, the DELPROF utility is your best bet for quickly and effectively cleaning up the mess caused by locally cached profiles.

In this Daily Feature, I’ll show you what DELPROF is and how it works. But first, let’s go over the problems that can occur when you use Explorer for the cleaning task, instead of DELPROF.

What’s wrong with using Explorer?
When you use Windows Explorer to delete locally cached user profiles on Terminal Services servers, you only delete the physical directory structure where the profiles are located. But profile information also exists in the server’s registry in several locations. By just deleting the profile directory, you don’t delete the associated entries and Security IDs (SIDs) in the registry. This presents a problem if you plan to use Folder Redirection in Group Policy.

If you’re using Folder Redirection and delete the profiles with Windows Explorer, the next time a user logs on, Terminal Server will re-create the directory structure stored for the user. However, Terminal Server will then check the registry and notice that the user has a profile with a SID already associated with it. Terminal Services will assume the SID is valid, assume the group membership list is current, and won’t apply Folder Redirection. However, for some odd reason, Terminal Services will go ahead and apply the rest of the Group Policy. Microsoft is considering supplying a possible fix for this oddity with the release of Service Pack 3 for Windows 2000.

Forcing a refresh of the Group Policy by using the Secedit command won’t help fix the problem. The only thing you can do at this point to force a change in Folder Redirection is to change the user’s group membership, basically adding or removing the user from a security group in Active Directory Users and Computers. The end result of using this deletion method is that you will not see the correct icons on the desktop or in the Start menu. In some cases, My Documents and Application Data folders will also not map correctly.

DELPROF to the rescue!
Microsoft provides a utility in the Windows NT and 2000 Resource Kits called DELPROF.EXE that can help you avoid all of the headaches you’d experience with Explorer. Using this utility ensures that all instances of the profile are properly removed from the registry. It also removes the directory structure from the Terminal Server. This is the only way locally cached user profiles should be removed to ensure a trouble-free environment.

The DELPROF.EXE utility can be run remotely on your administration workstation or directly on your server. DELPROF’s syntax is:
Delprof [/q] [/p] [/c:\\computername] [/d:days] [/?]

Switches you use with DELPROF include:

  • /q
    which runs DELPROF in quiet mode.
  • /i
    which ignores any errors that DELPROF might encounter.
  • /p
    which prompts for confirmation prior to deletion of the profile.
  • /c:
    where “\\computername” specifies the remote computer name on which you plan to delete profiles cached locally.
  • /d:
    where “days” represents the number of days that profiles had no activity.
  • /?
    which displays command line syntax help.

Before you run the utility, get your registry editor ready and make sure you make a good backup copy of your registry prior to any modification. Make sure no one is logged on to the Terminal Server from which you will delete profiles. If users are still logged on, the utility will fail while trying to delete a user that is already logged on because of the users’ open files.

Copy DELPROF.EXE to the server or workstation you want to run it from; open a command prompt and change directories to the location where you copied DELPROF.EXE. Type delprof /c:\\computername and press [Enter]. A prompt will ask you if you’re sure you want to delete the profiles. Type Y for yes or N for no. In the event that DELPROF fails to delete one or a number of profiles, run the command line again until you have deleted them all.

Once the command completes with no failed messages, double-check to make sure the profiles were actually removed from the Terminal Server by remotely browsing to the directory that was storing the profile. This can be done by clicking Start | Run and typing \\remotecomputername\c$ in the Run dialog box. Browse to the Profiles directory.

If any profiles are still there, you will have to resort to manually deleting them, either by using the Deltree command or by using Windows Explorer. When manually deleting these profiles, make sure you don’t delete the Default user and the All Users profiles. You don’t have to worry about this when using DELPROF, since it won’t delete either of these two profiles.

In order to avoid Explorer’s problem of retaining repetitive profile information in registry, you must also manually clean the profile’s associated registry keys from the registry. To manually remove registry keys, use REGEDIT. You can’t use Regedt32. If you’re connecting to a remote computer and not cleaning up a local registry, click on Registry in the File menu and select Connect To Network Registry. Enter the name of the computer you deleted profiles from and browse down in the registry to these two locations:

  • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Group Policy\
  • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\

Make sure no SID entries are still present in these two keys. If there are SIDs present, delete them. Be extremely careful that you don’t delete anything but the SIDs. SID entries or keys will look something like S-1-5-21-2000478354-1715567821-682003330-1005, the exact key varying from computer to computer. Close the registry. Now you can log back in to the Terminal Server and it will create the profiles fresh in the registry and on the hard drive.

When you’re running Terminal Services, your hard drive can quickly become cluttered with locally cached profiles. Save yourself a few headaches as well as a number of trips to the registry by using DELPROF to clean out these space-hogging profiles. While DELPROF might not clean everything out, it will certainly save you some valuable time and effort.