By David Wiseman (Administrator)Created 14 Jan 2006
My Rating:
Not Rated

Delete Local Profiles

Language:  VBScript


Delete all the local profiles stored on a computer.(All folders stored in the "C:\Documents and Settings\" folder with a few exceptions added.)

This script could be run as a start-up or shutdown script to stop windows saving copies of user profiles. Please note that there is a group policy setting to delete cached copies of roaming profiles, and running this script might impact logon performance. Please use this script with particular caution as it has the potential to delete user documents if folder redirection is not used. 

Line Numbers: On  Off      Plain Text
Const LocalDocumentsFolder = "C:\Documents and Settings\"

set objFSO = createobject("Scripting.FileSystemObject")
set objFolder = objFSO.GetFolder(localdocumentsfolder)

on error resume next

for each fldr in objFolder.SubFolders
	if not isexception( then
		objFSO.DeleteFolder fldr.path, True
	end if

Function isException(byval foldername)
	select case foldername
		case "All Users"
			isException = True
		case "Default User"
			isException = True
		case "LocalService"
			isException = True
		case "NetworkService"
			isException = True
		case "Administrator"
			isException = True
		case Else
			isException = False
	End Select
End Function


Got a useful script? Click here to upload!


  Post Comment
Order By:  
User Comments
Posted On: 7/18/2008 6:45:43 AM

Would there be a way to extend the script to also check the age of the profile before deleting it. For example, that only profiles older than 1 month should be deleted.

Posted On: 9/10/2008 12:36:18 PM

Although i do like scripts, There is a Microsoft utility that will let you to delete profiles. I use this on a regular basis.

Posted On: 1/18/2013 12:36:51 AM

Can I use this script as it is or should change some lines? can you answer fast. I am really in need of this. Thank you, Regards, Gary