Local Profiles

A

A Lake

Is there any way I can automatically delete local user profiles when a PC is
started/shutdown? I don't want to use roaming profiles for various reasons
and each group of 30 or so PCs needs a Default User profile on each to work.

I've tried using delprof but as this requires admin rights its not suitable
for use when anyone logs in.

My ideal scenario is:
1) Network user logs into PC and gets new profile from Default User
2) Group Policy applied
3) When user logs out, profile is deleted (or scheduled for delete on next
reboot)

Is this possible?
 
D

Doug Knox MS-MVP

You could create a Scheduled Task to do this, with the option to run when the computer starts. The Task would run a VBS file or executable that would scan the Documents and Settings folder for sub-folders other than the usual "system" accounts. If found, it would delete them. The following is a VB Script that will accomplish this for you. You can modify the list of folders that aren't deleted, as desired. Simply copy and paste the following into a Notepad file, save it with a VBS extension and point the Task to the VBS file you saved.

'-------------- Copy below this line -----------------------------
Dim fso, f, f1, fc, s, folderspec, DeleteIt, strName

'If your Documents and Settings folder is not on C:, or isn't
'called Documents and Settings, change the folderspec variable
'to the correct location.
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)

'Check to see if the folder name matches one you want to keep
'if so, then exit this subroutine

'Add more lines to exclude specific user folders from being
'deleted automatically. Delete lines to have those folders
'deleted anyway.

If strName = "Default User" Then Exit Sub
If strName = "NetworkService" Then Exit Sub
If strName = "LocalService" Then Exit Sub
If strName = "All Users" Then Exit Sub
If strName = "Administrator" Then Exit Sub

'Since the folder name didn't match any of the ones above
'we delete it
fso.DeleteFolder(folderspec & "\" & f1.name)

End Sub
'------------------ Copy above this line -----------------------
 
T

Torgeir Bakken \(MVP\)

Doug said:
You could create a Scheduled Task to do this, with the option to run when the computer starts. The Task would run a VBS file or executable that would scan the Documents and Settings folder for sub-folders other than the usual "system" accounts. If found, it would delete them. The following is a VB Script that will accomplish this for you. You can modify the list of folders that aren't deleted, as desired. Simply copy and paste the following into a Notepad file, save it with a VBS extension and point the Task to the VBS file you saved.

'-------------- Copy below this line -----------------------------
Dim fso, f, f1, fc, s, folderspec, DeleteIt, strName

'If your Documents and Settings folder is not on C:, or isn't
'called Documents and Settings, change the folderspec variable
'to the correct location.
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)

'Check to see if the folder name matches one you want to keep
'if so, then exit this subroutine

'Add more lines to exclude specific user folders from being
'deleted automatically. Delete lines to have those folders
'deleted anyway.

If strName = "Default User" Then Exit Sub
If strName = "NetworkService" Then Exit Sub
If strName = "LocalService" Then Exit Sub
If strName = "All Users" Then Exit Sub
If strName = "Administrator" Then Exit Sub

'Since the folder name didn't match any of the ones above
'we delete it
fso.DeleteFolder(folderspec & "\" & f1.name)


or better (in case of Read-Only files/folders:

fso.DeleteFolder folderspec & "\" & f1.name, True

or even better (to make the script continue even if encountering
a locked file:

On Error Resume Next
fso.DeleteFolder folderspec & "\" & f1.name, True
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top