Delete old profiles

V

Vijay

I want to delete old profile automatically from document and settings more
than 10 days , Old profile should be deleted automatically,
Should i use group policy or need to run bat files,

Please tell me the steps,
 
P

Pegasus [MVP]

Vijay said:
I want to delete old profile automatically from document and settings more
than 10 days , Old profile should be deleted automatically,
Should i use group policy or need to run bat files,

Please tell me the steps,

Here you go:
1. Copy & paste the code below into c:\Windows\DeleteFolders.vbs.
2. Unwrap any line that might have wrapped around.
3. Adjust Lines 01 and 02 to suit your environment.
4. Remove the line numbers.
5. Double-click c:\Windows\DeleteFolders.vbs. Note that the code
will prompt you before it deletes a profile folder.

[01] iAge = 10
[02] sExceptions = "Default User|Administrator|All
Users|LocalService|NetworkService"
[03] Set oFSO = CreateObject("Scripting.FileSystemObject")
[04] Set oProfiles = oFSO.GetFolder("c:\Documents and Settings")
[05]
[06] For Each oFolder In oProfiles.SubFolders
[07] If InStr(1, sExceptions, oFolder.Name, 1) = 0 Then
[08] If oFSO.FileExists(oFolder.Path & "\ntuser.dat") Then
[09] Set oFile = oFSO.GetFile(oFolder.Path & "\ntuser.dat")
[10] If DateDiff("d", oFile.DateLastModified, Now) > iAge Then
[11] iReply = MsgBox("Delete " & oFolder.Path & "?", vbYesNo)
[12] if iReply = 6 then oFSO.DeleteFolder oFolder.Path
[13] End If
[14] End If
[15] End If
[16] Next
 
G

Guest

Pegasus,

If you include a MessageBox then it isn't unattended

Good ole FileSystemObject from the scrun dll. Takes me back to VB6 days -
happy times :))

--
SPAMCOP User

Pegasus said:
Vijay said:
I want to delete old profile automatically from document and settings more
than 10 days , Old profile should be deleted automatically,
Should i use group policy or need to run bat files,

Please tell me the steps,

Here you go:
1. Copy & paste the code below into c:\Windows\DeleteFolders.vbs.
2. Unwrap any line that might have wrapped around.
3. Adjust Lines 01 and 02 to suit your environment.
4. Remove the line numbers.
5. Double-click c:\Windows\DeleteFolders.vbs. Note that the code
will prompt you before it deletes a profile folder.

[01] iAge = 10
[02] sExceptions = "Default User|Administrator|All
Users|LocalService|NetworkService"
[03] Set oFSO = CreateObject("Scripting.FileSystemObject")
[04] Set oProfiles = oFSO.GetFolder("c:\Documents and Settings")
[05]
[06] For Each oFolder In oProfiles.SubFolders
[07] If InStr(1, sExceptions, oFolder.Name, 1) = 0 Then
[08] If oFSO.FileExists(oFolder.Path & "\ntuser.dat") Then
[09] Set oFile = oFSO.GetFile(oFolder.Path & "\ntuser.dat")
[10] If DateDiff("d", oFile.DateLastModified, Now) > iAge Then
[11] iReply = MsgBox("Delete " & oFolder.Path & "?", vbYesNo)
[12] if iReply = 6 then oFSO.DeleteFolder oFolder.Path
[13] End If
[14] End If
[15] End If
[16] Next
 
P

Pegasus [MVP]

SPAMCOP User said:
Pegasus,

If you include a MessageBox then it isn't unattended

Good ole FileSystemObject from the scrun dll. Takes me back to VB6 days -
happy times :))

I know but I'm very reluctant to post a solution that deletes folders
without user confirmation. It would be quite easy to remove the user prompt
but then your "delprof" suggestion may be a more elegant solution.
 

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