Sign in to follow this  
Followers 0
jennico

TempDelete.au3 - Cleans Temp Directories

81 posts in this topic

#1 ·  Posted (edited)

Wondering why system is slow ? IE needs minutes to startup ?

Annoyed of cleaning up manually and the windows error messages when trying to do so ?

Try my little helper. It's small, fast and cute, without too many options.

TempDelete.au3

#cs
    ;#=#INDEX#===================================================#
    ;#  Title .........: TempDelete.au3
    ;#  Description ...: Clears (basic) Temporary Folders (incl. IE).
    ;#  Date ..........: 3.1.09
    ;#  Version .......: 1.5 (changed: added icons, added ini, fixed a bug)
    ;#  History .......: v 1.4  2.1.09    (changed @ProcessorArch to work with AutoIt v 3.3.x.x)
    ;#                   v 1.3  1.1.09    (changed: Processor arch, delete ActiveX, Recycler, Recent, RunMRU added, added shortcut)
    ;#                   v 1.2  30.12.08  (changed security check of paths, index.dat delete)
    ;#                   v 1.1  30.12.08  (changed syntax to please AU3Check)
    ;#                   v 1.0  30.12.08
    ;#  AutoIt Version : Written in 3.2.12.1 - no includes - everworking
    ;#                   Tested with 3.3.0.0
    ;#  OS ............: Written and working on XP Pro SP2 with IE6.
    ;#                   Though IE versions have varying temp directories, script should work with any combination.
    ;#  Remarks .......: Happy New Year !
    ;#                   Files in use cannot be deleted.
    ;#                   Index.dat will be deleted on reboot.
    ;#                   Use at own risk - No responsibility for damages.
    ;#                   Do not delete ActiveX elements before checking them !
    ;#  Author ........: jennico (jennicoattminusonlinedotde)
    ;#                   ©  2008 by jennico
    ;#===========================================================#
#ce

#NoTrayIcon

GUISetIcon("shell32.dll", -132, GUICreate("TempDelete  ©  2008 by jennico", 160, 230))

Dim $te = _CreateControl(1, "Temp Directory", 30, -3, "shdocvw.dll"), $t = _CreateControl(6, "", 111), _
        $hi = _CreateControl(0, "IE History", 154, 21), $ex = _CreateControl(3, "Cancel", 85), _
        $cm = _CreateControl(0, "CMDRun History", 70, -49, "progman.exe"), $ed = _CreateControl(4), _
        $co = _CreateControl(1, "IE Cookies", 134, -11, "shdocvw.dll"), $t = _CreateControl(5), $q, _
        $ti = _CreateControl(1, "Temporary Internet Files", 114), $go = _CreateControl(2, "Apply", 10), _
        $ax = _CreateControl(-1, "IE ActiveX", 174, -9, "explorer.exe"), $t = _CreateControl(7, "", 112), _
        $bi = _CreateControl(0, "C:\Recycler", 90, 32), $rc = _CreateControl(0, "Recent Documents", 50, -55)

If StringMid(@AutoItVersion, 3, 1) = 2 And @ProcessorArch = "X64"  Then $q = 64
If StringMid(@AutoItVersion, 3, 1) = 3 And @OSArch = "X64"  Then $q = 64

Dim Const $pv = "PendingFileRenameOperations", _
        $rg = "HKCU" & $q & "\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders", _
        $pe = "HKLM" & $q & "\SYSTEM\CurrentControlSet\Control\Session Manager", _
        $px = "HKLM" & $q & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\ActiveX Cache", _
        $ru = "HKCU" & $q & "\Software\Microsoft\Windows\CurrentVersion\Explorer\RUNMRU" 

GUISetState()

ControlFocus("", "", $go)

FileCreateShortcut(@ScriptFullPath, @ProgramsCommonDir & "\AutoIt v3\TempDelete  ©  by jennico.lnk"  _
        , "", "", " Clears (basic) Temporary Folders (incl. IE) ", "shell32.dll", "", 131)

Do
    Dim $ms = GUIGetMsg(), $tm = TimerInit()
    If $ms <> $go Then ContinueLoop
    WinMove("TempDelete", "", Default, Default, 450)
    GUICtrlSetData($ed, "===> Summary:" & @CRLF)
    If GUICtrlRead($cm) = 1 Then
        RegDelete($ru)
        GUICtrlSetData($ed, @CRLF & "=> CMDRun History Deleted" & @CRLF, 1)
    EndIf
    GUICtrlSetData($ed, @CRLF & "===> Deleted: " & Round(( _
            _GetSize(GUICtrlRead($te), FileGetLongName(@TempDir)) + _
            _GetSize(GUICtrlRead($rc), RegRead($rg, "Recent")) + _
            _GetSize(GUICtrlRead($bi), @HomeDrive & "\Recycler") + _
            _GetSize(GUICtrlRead($ti), RegRead($rg, "Cache")) + _
            _GetSize(GUICtrlRead($co), RegRead($rg, "Cookies")) + _
            _GetSize(GUICtrlRead($hi), RegRead($rg, "History")) + _
            _GetSize(GUICtrlRead($ax), RegRead($px, "0"))) / 1048576, 2) & " MB." & _
            @CRLF & "===> Done (" & Round(TimerDiff($tm) / 1000, 2) & " sec).", 1)
Until $ms = $ex Or $ms = -3

IniWriteSection("C:\TD.ini", "-", "30=" & GUICtrlRead($te) & @LF & "50=" & GUICtrlRead($rc) & @LF & "70=" & _
        GUICtrlRead($cm) & @LF & "90=" & GUICtrlRead($bi) & @LF & "114=" & GUICtrlRead($ti) & @LF & "134=" & _
        GUICtrlRead($co) & @LF & "154=" & GUICtrlRead($hi) & @LF & "174=" & GUICtrlRead($ax))

Func _GetSize($Ct, $Pa, $a = 0, $b = 0)
    If FileExists($Pa) = 0 Or StringRight($Pa, 2) = ":\"  Or StringRight($Pa, 1) = ":"  Then Return 0 * _
            GUICtrlSetData($ed, @CRLF & "=> " & $Pa & @CRLF & "Path invalid. No action taken." & @CRLF, 1)
    GUICtrlSetData($ed, @CRLF & "=> " & $Pa & @CRLF & "Before:  " & @TAB & _SetData($a, $Pa), 1)
    If $Ct = 1 Then _DeleteFiles($Pa, "*.*")
    GUICtrlSetData($ed, "After:  " & @TAB & _SetData($b, $Pa, $Ct), 1)
    If $b > 0 Then Return $a - $b
EndFunc   ;==>_GetSize

Func _SetData(ByRef $tp, $Pa, $Ct = 1)
    If $Ct = 4 Then Return "Nothing changed." & @CRLF
    $si = DirGetSize($Pa, 1)
    $tp = $si[0]
    Return Round($si[0] / 1048576, 2) & " MB  in  " & $si[1] & " File(s)  in  " & $si[2] & " Folder(s)." & @CRLF
EndFunc   ;==>_SetData

Func _DeleteFiles($Pa, $Ft)
    $Se = FileFindFirstFile($Pa & "\" & $Ft)
    If $Se = -1 Then Return DirRemove($Pa, 1)
    While 1
        $Fi = FileFindNextFile($Se)
        If @error = 1 Then Return DirRemove($Pa)
        If $Fi = ".."  Or $Fi = "."  Then ContinueLoop
        $Fi = $Pa & "\" & $Fi
        If StringInStr(FileGetAttrib($Fi), "D") Then _DeleteFiles($Fi, "*")
        If StringRight($Fi, 10) = "\index.dat"  Then RegWrite($pe, $pv, "REG_MULTI_SZ", "\??\" & _
                FileGetShortName($Fi) & @LF & @LF & RegRead($pe, $pv))
        FileDelete($Fi)
    WEnd
EndFunc   ;==>_DeleteFiles

Func _CreateControl($ty, $tx = "", $x = 10, $num = "", $dll = "shell32.dll", $re = 0)
    If $ty < 2 Then $re = GUICtrlCreateCheckbox($tx, 10, $x, 120 + 20 * ($x = 114), 20)
    If $ty < 2 Then GUICtrlSetState(-1, IniRead("C:\TD.ini", "-", $x, $ty))
    If $ty = -1 Then GUICtrlSetColor(-1, 0xF20000)
    If $ty = -1 Then GUICtrlSetTip(-1, "Do not check unless you know what you're doing !" & @CRLF & _
            "Folder may contain important applications !", "Delete ActiveX Elements", 2, 1)
    If $ty = 2 Or $ty = 3 Then $re = GUICtrlCreateButton($tx, $x, 200, 65)
    If $ty = 2 Then GUICtrlSetState(-1, 512)
    If $ty < 4 Then GUICtrlSetCursor(-1, 0)
    If $ty = 4 Then $re = GUICtrlCreateEdit("", 160, $x, 280, 215)
    If $ty = 5 Then GUICtrlCreateLabel("Please choose what to delete:", $x, $x, 145)
    If $ty = 6 Then GUICtrlSetBkColor(GUICtrlCreateLabel("", 10, $x, 140, 1), 0x808080)
    If $ty = 7 Then GUICtrlSetBkColor(GUICtrlCreateLabel("", 10, $x, 140, 1), 0xFFFFFF)
    GUICtrlSetResizing(-1, 258)
    If $ty < 2 And $x <> 114 Then GUICtrlSetResizing(GUICtrlCreateIcon($dll, $num, 132, $x, 18, 18), 258)
    Return $re
EndFunc   ;==>_CreateControl

As always in my programs : no includes, no problems with AutoIt versions.

I am not sure if I found all the temp folders from the registry. So please feel free to tell me what I missed.

Have fun

j.

Edit: v 1.1 i edited the silly au3check issue.

Edit: v 1.2 more secure (checks paths) and with index delete.

Edit: v 1.3 respects proc arch, creates shortcut, added options: Recent Documents, CMDRun History, C:\Recycler, IE ActiveX.

Edit: v 1.4 @OSArch macro to be working with AutoIt v 3.3.x.x

Edit: v 1.4.1 one error fixed

Edit: v 1.5 with icons and ini to save and load settings.

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites



Potentially good tool, however I get error:

D:\Scripts\TempDelete.au3(48,47) : ERROR: $tm already declared as parameter
    Dim $si = DirGetSize($Pa, 1), $tm = $si[0]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

this is definitely not an error.

$tm is declared ByRef, of course it can be redeclared (even if not ByRef, it can be redeclared). i don't know why people prefer SyntaxCheck to their common senses. i never understood this funny error message. it should be tilted.

script works, no matter what SyntaxCheck says. :) don't run it from SciTe.

j.

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

i cannot because it's ByRef.


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

i always wanted to discuss this issue.

maybe anyone can tell me:

1. in general : why can a parameter not be reassigned in a function ???

2. in specific : how am i supposed to use ByRef if 1.) is not allowed ???

and there are more problems in au3Check, e.g. cannot declare globally in function (why not ???). i think anyone should update au3Check (whoever made it).

j.

Edit: meanwhile I edited the code just to please au3check.

this was the original "errorous" syntax:

Func _SetData(ByRef $tp, $Pa, $Ct = 1)
    If $Ct = 4 Then Return "Nothing changed." & @CRLF
    Dim $si = DirGetSize($Pa, 1), $tp = $si[0]
    Return Round($si[0] / 1048576, 2) & " MB  in  " & $si[1] & " File(s)  in  " & $si[2] & " Folder(s)." & @CRLF
EndFunc   ;==>_SetData
Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

This should work: (as you already have)

Func _SetData(ByRef $tp, $Pa, $Ct = 1)
    $tp = $si[0]
Without Dim.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

well yes that's right, but i really cannot call it a scripting error. maybe a hint, maybe a question of style, okay, but it's not an error. au3check should not do that. of course you can dim a param in the function, why not ?

j.

(i just tested some scripts of mine, none of them passes au3check. this is really annoying. (i never used to run scripts from SciTe before).)

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

Actually thathas been a problem with AU3Check from the Get0go. But on the other hand, Dim is a bad policy as well. Dim is generally for arrays and 9 times out of 10 it's only being used to declare an empty array anyway. In most cases Global or Local will do the same thing. I remember some discussion a while ago about whether or not Dim should just be dropped as being redundent (archaic?) code.

The AU3Check warning about "Global variable assigned in Function, prefer top of file" is definitly just someone elses idea of good coding practice also based on out-dated coding styles. If it works then leave it alone, if it won't work then give me a warning.

I use a slightly modified return from AU3Check in one of my apps that allows the option of displaying all warnings and errors or just Errors. Don't even give me the warnings because I'm well aware that what I've done is considered to be poor, however there are situations where it can not be avoided. This applies in particular to that damn Variable possibly used before declaration. In my case it may well be but by the time the app finishes loading then everything is declared before any variables are actually called anyway. I have certain local UDF's which most definitly can not be called before a certain point and those ones will give me a warning every time.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

jennico, That is great work! Seems to work very well on my windows xp sp2.. Thanks!

Share this post


Link to post
Share on other sites

@Jennico

should add more function to do like ccleaner :)

Cheers, FireFox.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

thank you. glad if you like it ! it was really hard work to clean that up manually.

@firefox: what do you think of ? are there other folders to be cleaned ? maybe i missed some ? tell me, though i want to keep it simple (no reg clean, not too much confusing optios).

@geosoft:

I use a slightly modified return from AU3Check in one of my apps that allows the option of displaying all warnings and errors or just Errors. Don't even give me the warnings because I'm well aware that what I've done is considered to be poor, however there are situations where it can not be avoided. This applies in particular to that damn Variable possibly used before declaration.

how did you achieve that ? if there is a line that can be added on top of script, i would like to use it always.

i would appreciate if au3check (by default) does not stop on every single remark, only on real errors. using Dim for a param - it may be unconvenient, but definitely is not wrong. if i made an exe, nobody would ever notice it. at least, since there is that silly "ConsoleWrite" used in example scripts (which i would never do), users are practically forced to use SciTe in order to run scripts, and therefore au3check should urgently be updated ! it sometimes seems to me that AutoIt wants to "overteach" the users and punish the non-conformists.

when i started scripting (~25 years ago), i learned it on a 16kB (just imagine !) machine - a Commodore. so i got used to save every single bit. one redundant line could exceed the memory. that's why i like to put as many commands in one line as possible. i admit, today it is not necessary anymore, but efficiency will always symbolize a good scripting style, doesn't it ?

j.

Edit:

Dim is generally for arrays and 9 times out of 10 it's only being used to declare an empty array anyway. In most cases Global or Local will do the same thing.

i can not really agree to that. Dim is not made to exclusively assign arrays. on the other hand, if i use "Local" instead of "Dim", still persists the error message. that does not solve the problem. the error is due to redeclaring a parameter, and i cannot see a reason why they do not want me to do that. Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

A Regclean in autoit would be super cool! have it scan for non involved links and clear them out.

Share this post


Link to post
Share on other sites

I do it the easy way. Read the StdOut stream to a string and then parse the string before sending the results to an edit control which displays the results that I want.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

A Regclean in autoit would be super cool! have it scan for non involved links and clear them out.

Reg Cleaners are never cool. Genearlly they do more harm than good. Just run one that removes empty values against a system that has MSOffice installed to see the results of that foolishness.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

there has been done a bigger tool in autoit before. i don't remember the name. XPClean i think. or CleanScript ? i think, geosoft made that ? :)

this does really a lot of cleanups, but the more clean the more dangerous. i would not dare to script anything that deletes registry entries. i just wanted to make a simple and harmless tool.

@SoftVoile :

half the work is done yet. look into the registry: in HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders you find recent documents and other stuff to delete.

i will have to look up in the registry where netscape and firefox store their settings, and then they can be deleted as well.

the rest is easy to realize. maybe i do it, if it is not too much work.

j.


Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

Share this post


Link to post
Share on other sites

I did not write that. I have one of my own (customized for my system) but I've never released it. Primarily because it is customized. I did the IE favorites cleaner, perhaps that's the one I wrote that you are thinking of.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

no, a veerry big one, from a dev. i remenber he called it "the biggest cleaning tool you have ever seen" (something like that). will do a forum search.

j.

i found it. here. think this is XPClean (?)

another one by valuater here.

Edited by jennico

Spoiler

I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.OixB7.jpgDon't forget this IP: 213.251.145.96

 

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