Apr 102007
 

Occasionally Windows XP manages to stuff up its roaming profile, when this happens, resolving profile related problems can be difficult.  Schools running Community Connect 3 will benefit from the "Reset Profile" option in the System Management Console, however, profile problems may quickly return, as they often remain on several workstations. 

To help cure this problem on an RM Community Connect 3 network, there is a system in place called station tidy.  This is supposed to clean user profiles when they reach a certain age, however there have been reports that this does not work correctly.  So to to ensure that a users profile problems will not return is not guaranteed.

There is however a possible answer.  It is a quick and dirty(ish) script that will delete all folders in C:Documents and Settings, with the exception of system folders that are quite important.  The script has been coded taking advantage that the computers "System" account has full control of all files and folders in the Documents and Settings folder.

Why not use the Microsoft DELProf utility?  Yes why not indeed.  Through personal experience I have found that the DELProf utility doesn't always delete stale user profiles, it seems quite random and doesn't explain why it has left profiles that are clearly over x number of days old.  This is particulary the case when a domain account has been deleted.

If you are having problems with profiles building up on your workstations, then this might help.  Note however that this only deletes folders from the Documents and Settings folder on the hard disk and does not attempt to clean up the Windows Registry that also contains references to the profile folders.

The Script below will NOT work with Windows Vista, this is because the security features of Vista prevent the deletion of the User profiles folders.  There is a Group Policy setting that will do a similar job to DELProf that you can switch on: Computer Config > Admin Templates > System > User Profiles >Delete User profiles older than X days.

  1. On the file server, open Active Directory Users and Computers.
  2. Browse to the Organisational Unit that contains the computers that you wish to clear the profiles from. (Do NOT put this at the domain level, as this will then run on your domain controllers and produce undesirable results)
  3. Right Click on the Organisation Unit and choose the properties menu.
  4. Choose the Group Policy Tab, and click the New button.
  5. Give the policy a meaningful name "Delete Profiles from Workstations" for example
  6. Double click on to edit the new policy.
  7. Browse to Computer Configuration -> Windows Settings -> Startup/Shutdown Scripts -> Startup
  8. Right click on the empty part of the Group Policy Editor to add a new file.
  9. Click on the Show Files button.
  10. Now create a file called "cleanprofiles.vbs"
  11. Edit the file and paste the code from below (tip: copy it into wordpad first so that it retains formatting)
  12. Save and close the file.
  13. Back in Group Policy Editor, click on the Add button and select the script that you created.
  14. Close Group Policy.
  15. Allow the policy to propgate through the network then reboot the workstations.  It may require 2 reboots before the script runs.

When the script first runs, Windows XP will appear to hang on the "Running Computer Scripts" message, this is normal as it will have several hundred folders and files to delete.

The code is quite rough and is quite lazy in the way that it was coded.  If you need to exclude more profiles, you need to add an If Then End If block containing the name of the profile you wish to skip.  The script could also be modified so that folders that are x number of days old are deleted, rather than everything.

If you felt exceptionally talented, you could add code to tidy up the Windows Registry so that all traces of the profile are removed from the computer.  The key to tidy is HKLMSoftwareMicrosoftWindows NTCurrentVersionProfileList 

	ON ERROR RESUME NEXT	
' Clears user profiles on computer startup
' leaves the following folders
' Administrator
' RM Default User
' Default User
' All Users
' ClassMate
' Reference : http://msdn2.microsoft.com/en-us/library/9kcx47hd.aspx
dim oktodelete, fso, f, foldercollection
set fso = CreateObject("Scripting.FileSystemObject")
set f = fso.getfolder("C:Documents and Settings")
set foldercollection = f.subfolders
for each folder in foldercollection
oktodelete = true
if instr(1, folder.path, "Administrator") then
oktodelete = false
end if
if instr(1, folder.path, "RM Default User") then
oktodelete = false
end if
if instr(1, folder.path, "Default User") then
oktodelete = false
end if
if instr(1, folder.path, "All Users") then
oktodelete = false
end if
if instr(1, folder.path, "ClassMate") then
oktodelete = false
end if
if instr(1, folder.path, "LocalService") then
oktodelete = false
end if
if instr(1, folder.path, "NetworkService") then
oktodelete = false
end if
if oktodelete then
'wscript.echo "Deleting Folder : " & folder.path
fso.deletefolder folder.path, true
end if
next

 

 Posted by at 10:55 pm