Sign in to follow this  
Followers 0
kor

Want to delete profiles, but exclude things like default user, all users, etc.

6 posts in this topic

I am using this script and it seems to work great.

#Include <Date.au3>
#Include <File.au3>

$FileList=_FileListToArray("C:\Documents And Settings", "*", 2)

If @error Then
    Exit
EndIf

For $x = 1 to $FileList[0]
    $t = FileGetTime("C:\Documents And Settings\" & $FileList[$x], 0)
    $varTimeStamp = $t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5]
   
    $varTimeDifference = _DateDiff ("D", $varTimeStamp, _NowCalc())
    MsgBox (0, "Time Difference", "It's been " & $varTimeDifference & ' days since the profile "' & $FileList[$x] & '" was last accessed.')
   
    If $varTimeDifference >= 90 Then
;~   DirRemove ("C:\Documents And Settings\" & $FileList[$x], 1)
    EndIf   
Next

However the message box reveals that the default user, all users, administrator profile, local service and network service are all on the chopping block. I do NOT want to delete those profiles. Administrator I'm not really concerned about but it would be nice to keep it in there.

The big ones for me are being able to exclude default user, all users, local service and network service.

Is there a way to exclude those profiles by manually defining them? I don't have a lot of experience with arrays so I'm not sure how to exclude things like that.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try this

edit: added users

#Include <Date.au3>
#Include <File.au3>

$FileList=_FileListToArray("C:\Documents And Settings", "*", 2)

If @error Then
    Exit
EndIf

For $x = 1 to $FileList[0]
    $t = FileGetTime("C:\Documents And Settings\" & $FileList[$x], 0)
    $varTimeStamp = $t[0] & "/" & $t[1] & "/" & $t[2] & " " & $t[3] & ":" & $t[4] & ":" & $t[5]
   
    $varTimeDifference = _DateDiff ("D", $varTimeStamp, _NowCalc())
    MsgBox (0, "Time Difference", "It's been " & $varTimeDifference & ' days since the profile "' & $FileList[$x] & '" was last accessed.')

        if $FileList[$x] = 'Administrator' Then
            Sleep(100)
        ElseIf $FileList[$x] = 'localservice' Then
            Sleep(100)
        ElseIf $FileList[$x] = 'networkservice' Then
            Sleep(100)
        ElseIf $FileList[$x] = 'All Users' Then
            Sleep(100)
        ElseIf $FileList[$x] = 'Default User' Then
            Sleep(100)
        Else
        If $varTimeDifference >= 90 Then
            DirRemove ("C:\Documents And Settings\" & $FileList[$x], 1)
    EndIf   
EndIf

Next
Edited by lordicast

[Cheeky]Comment[/Cheeky]

Share this post


Link to post
Share on other sites

That worked great. thanks!

Is there a way to distinguish between a roaming profile and a local profile? If I look at the profiles advanced options in the windows advanced properties it will tell me... but right clicking on a particular profile folder I see nothing in there that says one way or the other. How does windows tell the difference?

Share this post


Link to post
Share on other sites

While this script serves it's purpouse, the dates for profiles when they were last accessed are mostly wrong. However I don't have any idea at the moment, how to modify it to check for real last access date?

Example.. for my profile current script says it's been 45 days since it has been last accessed, but I'm using it daily :)

Any suggestions welcome...

Share this post


Link to post
Share on other sites

works just fine for me, 0 days. I could not replicate your issue? what version of windows you have?


[Cheeky]Comment[/Cheeky]

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

That might be the issue.. Windows 7 :)

edit:

Just tried it on WinXP, it reports 0 days for All Users and Default User, but for user currently logged on it reports 28 days. So, problem still exists..

Edited by skysel

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0