Jump to content

Empty All User Temps


ripdad
 Share

Recommended Posts

Empties files and folders in:

All Profile Temps

All Profile Cookies

All Profile Temporary Internet Files

Tested on WinXP

Will most likely need to be modified for another OS

Disclaimer: Use at your own risk!

; File: EmptyAllTemps.au3 - Version 2
; Released: May 03, 2010 - by ripdad
; Tested on XP only
;
; Empties files and folders in:
;
; Windows Temp
; All Profile Temps
; All Profile Cookies
; All Profile Temporary Internet Files
;
If Not (@OSVersion = 'WIN_XP') Then Exit
If Not IsAdmin() Then Exit
;
Local $answer = MsgBox(8228, ' Confirm Empty', 'Empty All Temp Folders ?  ')
If $answer = 7 Then Exit
;
Global $pffff, $pffnf, $pextd, $tally = 0
;
_EmptyAllTempsXP()
;
MsgBox(8256, ' Empty All Temps - Finished', 'Items Processed: ' & $tally & @CRLF & @CRLF & 'Some Files and Folders May Be In Use  ')
;
Func _EmptyAllTempsXP()
    Local $sCook = ('\Cookies\')
    Local $sTemp = ('\Local Settings\Temp\')
    Local $sInet = ('\Local Settings\Temporary Internet Files\Content.IE5\')
    Local $RootFolder = (@HomeDrive & '\Documents and Settings\')
    Local $UserFolder, $TargetFolder
    Local $ProfileList = FileFindFirstFile($RootFolder & '*')
    Do
        $UserFolder = FileFindNextFile($ProfileList)
        If @error Then ExitLoop
        If FileExists($RootFolder & $UserFolder) Then; Confirm User Folder Exist
            $TargetFolder = ($RootFolder & $UserFolder & $sCook)
            _ProcessProfileXP($TargetFolder)
            $TargetFolder = ($RootFolder & $UserFolder & $sInet)
            _ProcessProfileXP($TargetFolder)
            $TargetFolder = ($RootFolder & $UserFolder & $sTemp)
            _ProcessProfileXP($TargetFolder)
        EndIf
    Until @error
    FileClose($ProfileList)
    $TargetFolder = (@WindowsDir & '\Temp\')
    _ProcessProfileXP($TargetFolder)
    ToolTip('', '', '')
EndFunc
;
Func _ProcessProfileXP($pTarget)
    If FileExists($pTarget) Then; Confirm Target Folder Exist
        $pffff = FileFindFirstFile($pTarget & '*')
        Do
            $pffnf = FileFindNextFile($pffff); Process Profile Folder
            If @error Then ExitLoop
            If ($pffnf = 'desktop.ini') Or ($pffnf = 'index.dat') Then ContinueLoop
            $pextd = @extended
            FileSetAttrib($pTarget & $pffnf, "-RASHNOT"); Remove Attributes
            Sleep(50); Required to slow this puppy down
            If $pextd = 0 Then FileDelete($pTarget & $pffnf); Item is a File
            If $pextd = 1 Then DirRemove($pTarget & $pffnf, 1); Item is a Folder
            $tally += 1; Just for Show
            ToolTip(' Empty All Temps - Items Processed: ' & $tally & @CRLF & $pTarget & $pffnf, 0, 0)
        Until @error
        FileClose($pffff)
    EndIf
EndFunc
;

Update: May 06, 2010 - Version 2.1 - umm, added: "FileClose($ProfileList)"

I wasn't really satisfied with the way version one was written - even though it worked fine.

So, after some great thought ... I've decided to break it up into 2 separate functions:

Function #1 handles the navigating of profile folders

Function #2 carries out the commands given for it

This improves the script tremendously with less code and loops.

The benefits are better speed and efficiency with extra error handling.

Also added remove attributes to catch those mean hidden ones.

.

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

You will need "Admin Rights" to use it in your main script.

It's possible, there might be a problem if a Profile is made private.

Although, there should be enough error handling in it to handle this event.

--- Also ---

If you want to adapt to your OS or your specific needs, then do this in your testing:

comment out the FileDelete and DirRemove lines and write in a MsgBox to make sure

you have the proper folders and files.

This script could also be adapted to modify and/or install folders and files.

Plus, you could get file and folder properties from each Profile (great for network management).

Could also be used as a search function.

It could have many uses .. just replace FileDelete and DirRemove with your commands

and it will process all Profiles. Remember to test with MsgBox first!

.

Edited by ripdad

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

  • 3 years later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...