Jump to content

Recommended Posts

Posted

I'm looking at Windows 7 to replace some of our old XP machines. One of the things I haven't found a way of doing is removing old profiles from the PC on reboot.

 

In our current XP system (no roaming profiles, with the local Default user profile configured per PC type) we run a script on machine startup to delete any profiles that belong to students etc but leaves system profiles/admin profiles etc.

 

Obviously this doesn't work with Windows 7 or Vista as any deleted profiles means the user cannot login without errors the next time.

 

Is there a way to remove profiles like this in Windows 7? Basically I want the 'clean start' mechanism I have now - plus preventing the PC from having 100s of profiles stored on it.

Posted

I've heard there is a GPO setting that does that in Server 2008 (may well be included on the ADMX for Windows 7)-

 

Computer Configuration->(Policies (WS2K8 only)->)Administrator Templates->System->User Profiles

 

Can either delete after a certain number of days or not store them at all from what I've read.

  • Thanks 1
Posted
Would you mind sharing the script that you use on Windows XP? I want to something VERY similar to that.

 

Thanks in advance.

 

Is this any help? A batch file that deletes all but specified profile folders...

 

@echo off

rem ***Created by CW 21-08-2007***
rem ***Modified by CW 20-08-2008***
rem ***Clear out all locally stored profiles on a workstation***


title Remove Local Profiles
dir /b/ad "C:\Documents and Settings" > %temp%\allusers.txt
find /v /i "Administrator" < %temp%\allusers.txt > %temp%\allusers1.txt
find /v /i "All Users" < %temp%\allusers1.txt > %temp%\allusers2.txt
find /v /i "Default User" < %temp%\allusers2.txt > %temp%\allusers3.txt
find /v /i "LocalService" < %temp%\allusers3.txt > %temp%\allusers4.txt
find /v /i "NetworkService" < %temp%\allusers4.txt > %temp%\allusers5.txt
find /v /i "user" < %temp%\allusers5.txt > %temp%\allusers6.txt
find /v /i "Xp user" < %temp%\allusers6.txt > %temp%\allusers7.txt
echo.
echo.
cls
echo.
echo.
echo Deleting all locally stored profiles,
echo except Administrator, All Users, Default User, LocalService, NetworkService, user, and XP User.
echo.
echo Please wait...
echo.
for /f "tokens=*" %%U in (%temp%\allusers7.txt) do (
rmdir /q /s "C:\Documents and settings\%%U" )
del /f /q %temp%\allusers*.txt
echo.
echo Operation complete.
pause
exit

  • Thanks 2
Posted

This is the vb script I use- very similar to above:

 

Dim fso, f, f1, fc, folderspec, strName

folderspec = "C:\Documents and Settings"

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(folderspec)
Set fc = f.SubFolders

For Each f1 in fc
   CheckNames(f1.name)
Next

Set fso = Nothing

Sub CheckNames(strName)

    If Ucase(strName) = "DEFAULT USER" Then Exit Sub
    If Ucase(strName) = "NETWORKSERVICE" Then Exit Sub
    If Ucase(strName) = "LOCALSERVICE" Then Exit Sub
    If Ucase(strName) = "ALL USERS" Then Exit Sub
    If UCase(strName) = "ADMINISTRATOR" Then Exit Sub
    ' Add as many of these as you need -one for each profile you DON'T want to delete!
 
    On Error Resume Next
    fso.DeleteFolder folderspec & "\" & f1.name, True


End Sub

 

I've got this running on machine startup - its worked a treat for around 5 years now!

Posted

As per the OP's post you should be aware that these scripts may have a consequence of preventing the user whose profile you deleted from logging on again in Windows 7 and Vista.

 

Deleting the directory does not remove the user from the computer entirely and Windows is expecting the profile to be in that location- when it isn't it won't allow the user to log on. The usual System Properties -> Advanced route is supposed to work and I have read about GPOs (see earlier in the thread) but have no real life experience of either.

 

I do know firsthand that people have had problems with their legacy scripts on Windows Vista/7 though and although I'm sure everyone else in the thread is aware of this I just want to labour the point in case someone googling takes the advice from here and applies it to a Vista/7 setting.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...