Possible to have a batch file that....

Soldato
Joined
18 Oct 2002
Posts
10,080
Location
At home
Hi,

On our terminal servers we set a GP so when users log out it deleted the roaming profile. However some don't go for whatever reason.


Is it possible to write a batch file that maybe every night deletes all the stale profiles in C:\doc and settings.

Will have to leave the default ones there though. Can you do exclusions ?
 
The usual cause of a profile not deleting is open registry keys in the profile which don't close before the timeout.

UPHClean is a great utility which runs as a service and unloads the users profile hive on logoff to allow the GP to sucessfully delete them.

Download is free too.

There's also a registry key on the server called deleteroamingcache (a search should find it) which you can set to 1 to enable. It does what it says on the tin.
 
We have it deleting profiles on shutdown, never had any trouble with folders not deleting. Can still put the script up here tomorrow if you want :)
 
This runs on shutdown, so normally once a day.

Code:
ON ERROR RESUME NEXT

ProfPath = "C:\Documents and Settings\"

Dim fso
Dim aFolder
Dim aSubFolder

Set fso = createobject("Scripting.FileSystemObject")

Set wshShell = CreateObject("WScript.Shell")
strUser = wshShell.ExpandEnvironmentStrings("%USERNAME%")

Set aFolder = fso.GetFolder(ProfPath)
Set bSubFolder = aFolder.Subfolders

For Each aSubFolder in bSubFolder
  Select Case lcase(aSubFolder.Name)
    Case "administrator", "all users", "default user", "localservice", "networkservice"
      'Ignore
    Case strUser
      'Ignore
    Case Else
      fso.DeleteFolder(ProfPath & aSubFolder.Name),True
  End Select
Next
 
Last edited:
This runs on shutdown, so normally once a day.

Code:
ON ERROR RESUME NEXT

ProfPath = "C:\Documents and Settings\"

Dim fso
Dim aFolder
Dim aSubFolder

Set fso = createobject("Scripting.FileSystemObject")

Set wshShell = CreateObject("WScript.Shell")
strUser = wshShell.ExpandEnvironmentStrings("%USERNAME%")

Set aFolder = fso.GetFolder(ProfPath)
Set bSubFolder = aFolder.Subfolders

For Each aSubFolder in bSubFolder
  Select Case lcase(aSubFolder.Name)
    Case "administrator", "all users", "default user", "localservice", "networkservice"
      'Ignore
    Case strUser
      'Ignore
    Case Else
      fso.DeleteFolder(ProfPath & aSubFolder.Name),True
  End Select
Next

as a batch file, how does that work ?? if a script umm how does that work ? :p
 
Back
Top Bottom