If Not @LogonMode
Break On
Else
Break Off
EndIf
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('NoMacrosInStrings','On')
$SO=SetOption('WrapAtEOL','On')
Dim $ProfilesDirectory, $Profiles, $CleanTemp
If InGroup(@WKSTA+'\'+SidToName('S-1-5-32-544'))
;User has Admin rights so clean all the temporary file locations
$ProfilesDirectory = ExpandEnvironmentVars(ReadValue('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList','ProfilesDirectory'))
$Profiles = Dir ($ProfilesDirectory)
While $Profiles <> '' And Len($ProfilesDirectory)>15
If $Profiles
If GetFileAttr($ProfilesDirectory+'\'+$Profiles+'\Local Settings\Temp') & 16
If Len($ProfilesDirectory+'\'+$Profiles)>25
$CleanTemp = CleanDirectory($ProfilesDirectory+'\'+$Profiles+'\Local Settings\Temp','*.*',2)
EndIf
EndIf
EndIf
$Profiles = Dir ()
Loop
Dim $WinDir
$WinDir = ReadValue('HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion','SystemRoot')+'\'+'TEMP'
$CleanTemp = CleanDirectory($WinDir,'*.*',2)
Else
;User does not have Admin rights so only clean the users temporary files
Dim $CurrentUserTemp
$CurrentUserTemp = ExpandEnvironmentVars(ReadValue('HKCU\Environment','TEMP'))
If Len($CurrentUserTemp)>15
$CleanTemp = CleanDirectory($CurrentUserTemp,'*.*',2)
EndIf
EndIf
;Deleting these temporary files coud easily generate an error
;so having an error is often expected at this point
Exit @ERROR
;************************************
; UDF (User Defined Functions)
; DO NOT MODIFY BELOW THIS POINT
;************************************
Function CleanDirectory($directories, $filter, optional $olderas, $countonly)
Dim $rc, $timediff, $filename, $filefilter, $tempdir
Dim $filecount, $dircount
$dircount=0
$filecount=0
$olderas=iIf(Val($olderas)>0,Val($olderas),0)
$countonly=iIf(Val($countonly),1,0)
If not (VarType($directories) & 8192)
$directories=Split($directories,'')
EndIf
If not (VarType($filter) & 8192)
$filter=iIf(Trim($filter),$filter,'*.*')
$filter=Split($filter,'')
EndIf
For Each $tempdir In $directories
If $tempdir<>'' And Exist($tempdir)
For Each $filefilter In $filter
If $filefilter<>''
$filefilter=fullfile($tempdir,$filefilter)
$filename=Dir($filefilter,1)
While $filename<>'' And @ERROR = 0
If $filename<>'.' And $filename<>'..'
$filename=fullfile($tempdir,$filename)
If GetFileAttr($filename) & 16
$rc=CleanDirectory($filename,$filter,$olderas,$countonly)
If InStr($rc,',')
$rc=Split($rc,',')
$dircount=$dircount+$rc[0]
$filecount=$filecount+$rc[1]
EndIf
$rc=SetFileAttr($filename,128)
If not $countonly
RD $filename
If not @ERROR
$dircount=$dircount+1
EndIf
EndIf
Else
$timediff=DateMath(@DATE,Left(GetFileTime($filename),10))
If $timediff>=$olderas
If $countonly
$filecount=$filecount+1
Else
$rc=SetFileAttr($filename,128)
Del $filename /c /f /h
If Not @ERROR
$filecount=$filecount+1
EndIf
EndIf
EndIf
EndIf
EndIf
$filename=Dir('',1)
Loop
EndIf
Next
EndIf
Next
$CleanDirectory=''+$dircount+','+$filecount
EndFunction
Function FullFile($p1, optional $p2)
Dim $p,$l
If VarType($p1) & 8192
$p1=Join($p1,'\')
EndIf
If VarType($p2) & 8192
$p2=Join($p2,'\')
EndIf
$p=$p1+'\'+$p2
$l=iIf(Right($p,2)='\\','\','')
$p=iIf(Right($p,1)='\',Left($p,-1),$p)
If InStr($p,'\\')
$p=FullFile(Join(Split($p,'\\'),'\'))
EndIf
If Left($p,1)='\' And Left($p,2)<>'\\'
$p='\'+$p
EndIf
$FullFile=$l+$p
EndFunction
Function DateMath($ExpD1,$ExpD2)
Select
Case InStr($ExpD1,'/') And InStr($ExpD2,'/')
$DateMath=serialdate($ExpD1)-serialdate($ExpD2)
If $DateMath<0
$DateMath=$DateMath*-1
EndIf
Case InStr($ExpD1,'/') And 1-InStr($ExpD2,'/')
$ExpD2=0+$ExpD2
$Datemath=SerialDate(SerialDate($ExpD1)+$ExpD2)
Case 1 ; incorrect parameters passed
EndSelect
EndFunction
Function SerialDate($ExpD)
Dim $z,$h,$a,$b,$c,$y,$m,$d
If InStr($ExpD,'/')
$y=Val(SubStr($ExpD,1,4))
$m=Val(SubStr($ExpD,6,2))
$d=Val(SubStr($ExpD,9,2))
If $m<3
$m=$m+12
$y=$y-1
EndIf
$SerialDate=$d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306
Else
$z=0+$ExpD+306
$h=100*$z-25
$a=$h/3652425
$b=$a-$a/4
$y=(100*$b+$h)/36525
$c=$b+$z-365*$y-$y/4
$m=(5*$c+456)/153
$d=$c-(153*$m-457)/5
If $m>12
$y=$y+1
$m=$m-12
EndIf
$m=Right('0'+$m,2)
$d=Right('0'+$d,2)
$SerialDate=''+$y+'/'+$m+'/'+$d
EndIf
EndFunction