Deleting a Local User Profile - Not as easy as one Might Assume

by Helge Klein on 10/16/2008 | 19 Comments | 83,073 Views

In many environments it is a common practice to delete user profiles prior to conducting tests in order to start with a clean slate. However, this may prove more difficult than anticipated.

Most people think that a local user profile only consists of the directory %USERPROFILE% typically located below C:\Users on Vista and Server 2008 (and newer). But there is more. Windows keeps track of the local profile incarnations in the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList. For each locally stored profile a subkey is created whose name is set to the profile owner’s SID. Here is the content of a sample ProfileList subkey:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\S-1-5-21-1659004503-1788223648-1417001333-500]
“ProfileImagePath”=”%SystemDrive%\Documents and Settings\Administrator”
“Sid”=hex:01,05,00,00,00,00,00,05,15,00,00,00,57,66,e2,62,a0,20,96,6a,75,b9,75,54,f4,01,00,00
“Flags”=dword:00000000
“State”=dword:00000100
“CentralProfile”=”"
“ProfileLoadTimeLow”=dword:224c9af0
“ProfileLoadTimeHigh”=dword:01c92f98
“RefCount”=dword:00000000
“RunLogonScriptSync”=dword:00000000
“OptimizedLogonStatus”=dword:0000000b

 

How Not to Delete a Profile

Now, what happens if you simply delete the user profile directory below C:\Users without modifying the registry? The next time the user logs on Windows displays a balloon tip whining that Windows could not load the user profile and that the user was logged on with a temporary profile. Is that bad? Yes! Temporary profiles are a last resort if Windows cannot load the user profile. Upon logoff they are deleted and all data is lost. That certainly is a reason to avoid them.

The Right Way

If you need to delete a profile, use one of these methods:

  • Use my command-line tool Delprof2
  • If deleting manually make sure to delete both the profile directory and the associated ProfileList subkey
  • Open the control panel applet “System Properties” by running sysdm.cpl and delete the profile from there (on Windows 7 the corresponding tab is accessible by running "SystemPropertiesAdvanced.exe")

What if I Already Deleted a Profile the "Wrong" Way?

If Windows finds a ProfileList subkey matching your SID without an associated profile directory it backs up the ProfileList subkey. Prior to creating the temporary profile the ProfileList subkey is renamed to SID.bak. About the reason for that strange behavior I can only speculate. Maybe someone thought this would facilitate restoring the original state from a backup.

Whatever the reason, once you got a temporary profile the SID.bak key lingers in the registry. It needs to be deleted to get back to normal profile behavior.

What About XP and Server 2003?

The behavior described in this article applies to Vista, Windows 7 and Server 2008 (including R2). Their predecessors XP and Server 2003 use a more simplistic approach. If a ProfileList registry subkey exists but the corresponding directory is not accessible, they simply create a new local profile and overwrite the data in the ProfileList key. Not even an event is logged to the Windows event log.

This behavior is certainly simpler but at the same time much more realistic. Not every change is for the better…

References

MS KB: A temporary profile is loaded after you log on to a Windows Vista-based system
MS KB: A temporary user profile is created every time that you log on to a Windows Vista-based computer that is connected to a domain

+++ Your opportunity +++ Use Profile Migrator 2, the new sepago product that makes migrating user personalities between different platforms a breeze.! Download your free version now!

19 responses for "Deleting a Local User Profile - Not as easy as one Might Assume"

I would also be interested as

I would also be interested as to why Vista works this way, XP days you could just delete the old profile, no registry stuff, this had me scratching my head, thanks for the article.

Cheers

Oliver

but I have a 2008 terminal

but I have a 2008 terminal server that uses local profiles (we dont use terminal server roaming profiles), inevitably the profiles fill up the disk

Is there an automated way to delete the profiles? It's just not good to have to keep deleting profiles manually :(

[...] Steven asked in

[...] Steven asked in response to my article on how not to delete local user profiles for the correct way to script the deletion of user profiles. Here is how. For completeness sake I [...]

Hello, Manually deleting the

Hello,

Manually deleting the ProfileList key and Directory isn't enough. I have create a DeleteProfile.vbs script that will automatically delete profiles from a workstation/server. The nice thing is it is a script so you can modify it and/or learn from it.

http://www.theshonkproject.com/index.php?option=com_content&task=view&id...

Joe

So i did it the "wrong" way.

So i did it the "wrong" way. Then I went in and deleted the SID.BAK.
Now when I attempt to login it says, "ACCESS DENIED" ...
Any ideas?

Logon as administrator and go

Logon as administrator and go into Computer - properties - Advanced Settings - Advanced tab - User Profiles and delete the profile there.

This has been useful, but on

This has been useful, but on 2008 terminal server, the folders in the users directory cannot be deleted through system- profiles as the article suggests as they don't exist there. All I've got in profiles are the administrator profiles, but I've got thirty or more users in the c:\users folders. I found that deleting the user folder, then deleting the registry key for the user as suggested worked.

Hello Im dimented Cannot

Hello
Im dimented
Cannot delete profiles from c:\users in windows 7.
Use deleteprofile.vbs - it cannot delete.
Scheduled task run under system does not delete the folders either.
help appreciated.
Colin

Thank you very much for an

Thank you very much for an informative blog!

thanks so much for the info,

thanks so much for the info, I had been unable to log on to my profile on the domain cos I deleted it but the info here really helped. I located the registry key with .bak and deleted it and now I can log on normally.

helpful info, was able to fix

helpful info, was able to fix my user account on the domain.
thanks.

thankssssssssssssssssssssssss

thanksssssssssssssssssssssssssssss

Helge - great information.

Helge - great information. I've been pulling my hair out for 2 days on this issue.

Dave

For programmers: use the

For programmers: use the DeleteProfile API in userenv.dll, see http://msdn.microsoft.com/en-us/library/bb762273(VS.85).aspx

Helge, what is the

Helge, what is the difference, if any, between deleting a profile via the System control panel and running 'net user [username] /delete'? Do either of these methods leave any traces in HKLM\SAM or HKLM\Security?

Also, could you possibly do a post outlining the meaning of and interpretation of the values under ProfileList\[SID-RID]? I'd like to know what Flags, State, CentralProfile, RefCount and OptimizedLogonStatus mean, in particular.

Drewfus, deleting a profile

Drewfus,
deleting a profile via "systempropertiesadvanced.exe" (Win7) does not delete the user account. "Net user /delete", on the other hand, deletes the user account, but not the profile.
I'll consider answering the other question in an article.
Thanks for your suggestions and comments.

Thanks Helge.

Thanks Helge.

thanks a lot .great job

thanks a lot .great job man.............

Good information thanks. For

Good information thanks.

For others, I'll share an issue and the fix from here that helped.

Moved workstation from old domain to new domain after a server rebuild (upgraded server). Changed the server name but kept the same domain name. And what a headache. Found had to remove all the SIDs as mentioned above manually on each machine. Lots of odd issues... implementing procedures above sorted it..