Deleting Server 2008 R2 profiles: NTUSER.DAT

terminal-serverwindows-server-2008

Having an issue with deleting user profiles on server 2008 when they become corrupt, we have successfully done this now by closing a process but it killed the server and forced a restart, not to bad as we are testing this server and only had 2 users on.

Is there any safe/quick way to do this via a script ?

Best Answer

ntuser.dat is a registry hive file that contains the registry entries associated with the profile. The kernel itself has the file open; the hive has to unloaded to unlock the file. You can force it to unload with reg unload, though you'll need the SID of the user that owns the profile. There is a related "classes" hive that expands HKEY_CLASSES_ROOT for each profile as well.

reg unload HKEY_USERS\S-1-5-21-1555713158-3015222722-1959872020-2924
reg unload HKEY_USERS\S-1-5-21-1555713158-3015222722-1959872020-2924_Classes

This applies to all versions of Windows since XP and there is something similar in all the previous versions of WinNT as well.

In general, it would be better to let Windows unload the profile itself, by removing the open references to it.