Deleting User Profiles - Correctly

by Helge Klein on 12/03/2008 | 8 Comments | 22,843 Views

Commenter 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 start with the manual method.

Deleting Profiles Manually

 

  1. Open the control panel applet "System Properties" and navigate to the tab "Advanced". I know of the following shortcuts for this often needed dialog box:

    • Press Win+Break
    • Press Win+R to open the run dialog box. Type in control sysdm.cpl,,3 and press enter. Note there must not be entered a space in front of the commas.
  2. Click on the settings button in the user profiles section.
  3. In the dialog that appears, choose the appropriate user profile and click on delete. Note: you must be an administrator for the delete button to even show up. And: you cannot delete your own profile.

Deleting Profiles Automatically

Microsoft's delprof utility can be used to delete all local(ly cached) user profiles. Optionally, only profiles not used for a specified number of days are deleted. Another option (/r) restricts the deletion to locally cached roaming profiles.

Please note: By default, delprof deletes all profiles! It does, however, ask for confirmation before each delete, unless the parameter /q is specified.

Usage examples:

Delete all cached copies of roaming profiles on the local machine:

delprof /q /i /r

Delete all profiles not used for 10 days on computer server:

delprof /q /i /c:\\server /d:10

Microsoft's Delprof does not work on operating systems newer than Windows XP/2003. It is not compatible with Windows 7 and 2008 R2. To fill the void I have written a syntax-compatible successor called Delprof2 which works on all versions of Windows and is even more powerful. Find more information and download Delprof2 here.

References

MS KB: How To Delete User Profiles by Using the User Profile Deletion Utility (Delprof.exe) in Windows 2000

+++ Profile Migrator 2 - Ein neuer Desktop, ein frisches Benutzerprofile und alle bewährten Einstellungen und Daten. Jetzt kostenlos und unbefristet testen!

8 responses for "Deleting User Profiles - Correctly"

Hello! I've got a profile

Hello!

I've got a profile with status "temprorary" in the sysdm-windows and want to delete it, so that the user gets his "normal" profile back which is stored on a share. With delprof the profile isn't listed, so who would I delete this file correctly?

When I log in with this user, the profile is loaded into c:\documents and settings\temp...

Thanks!
Udo

Solved - I've deleted the

Solved - I've deleted the reg-structure in HKEY_Users for this user, so I could delete the TEMP-profile in C:\documents and settings. After a re-login the old profile was used.

Udo

From my earlier post:

From my earlier post: http://blogs.sepago.de/helge/2008/10/16/deleting-a-local-user-profile-no...

"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." (Applies to Vista/2008)

Good to hear the problem is

Good to hear the problem is solved ;-)

On my site, I do have a

On my site, I do have a better version of DelProf.exe and it is script based to it easy modify.

Joe

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

Also note: Users should be running UPHClean... DO NOT DELETE a profile that is LOAD or has handles associated to it.

Joe, your script looks

Joe,

your script looks impressive! Thanks for pointing me to it.

Hi Klein, I regularly read

Hi Klein, I regularly read you Blog and I can finally contribute something.

Just a little note, we had been using DelProf.exe on Windows 2008 servers and Vista machines. We are setup with Roaming Profiles and folder Redirection, Delprof gets ride of the user profile in the registry and c:\users but it fails to remove any cached data used by the offline files (Stored in c: Windows\CSC)

The result would be that after removing a profile with Delprof and logging back on with the roaming profile, the Redirected Folders would fail to find the correct network path, using the local cached data in c:\Windows\CSC and at this point the only solution was to add the following registry entry Reg \\%TargetCmp%\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Csc\Parameters /v FormatDatabase /d1 /t REG_DWORD /f in order to flush the Off Line cache at Reboot.

After searching for a while I found that in Vista/2008 the only "correct" way to delete profiles by script is the use the WMI Win32_UserProfile. class

For example we now use the following script the delete roaming profiles remotely :

TITLE %~nx0
@Echo on
cls

@echo .
Set /p TargetCmp=Enter computername on which we will delete all the roaming profiles:

for /f "tokens=1,2" %%a in ('wmic /node:"%TargetCmp%" path win32_UserProfile get RoamingConfigured^,Sid^|find "TRUE"') do (
echo %%a echo %%b
wmic /node:"%TargetCmp%" path win32_UserProfile where Sid="%%b" Delete
)

Pause
Exit

Indeed, the client-side cache

Indeed, the client-side cache (CSC) also needs to be cleaned up.
Thanks for contributing the script!