Page 1 of 1 1
Topic Options
#188685 - 2008-07-10 11:33 PM Clearout the OutlookSecureTempFolder to prevent Unable to Save File errors
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
This script is designed to clean out the OutlookSecureTempFolder which can cause issues for users trying to launch or save files if this folder already has files with the same name saved there, and/or the folder is filling up. Currently this affects both Microsoft Outlook 2003 and 2007 and there does not appear to be a fix from Microsoft for it yet.
I have supplied links to some MS KB articles that discuss it further.

Deleting these temporary files corrects the issue.


; Error message when you try to open or save an e-mail attachment in Outlook: "Cannot create file" 
; http://support.microsoft.com/kb/305982
; Attachments remain in the Outlook Secure Temporary File folder when you exit Outlook 2003 or Outlook 2007
; http://support.microsoft.com/kb/817878
; OL2000: Attachment Temporary Files Always Stored in Same Location
; http://support.microsoft.com/kb/249793
; OL2000: Error Message Appears When You Open a Word Template That Is in an Outlook Store
; http://support.microsoft.com/kb/296416
; Error message when you try to track an HTML-formatted e-mail message that contains an image in the signature
; in Microsoft Dynamics CRM 3.0: "An error occurred promoting this item to Microsoft CRM"
; http://support.microsoft.com/kb/933234

;*** REQUIRES the following UDF scripts to function correctly.
;*** ClearOutlookTemp (not published but posted here in this script)
;*** CleanDirectory http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=82624
;*** FullFile http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=82207
;*** DateMath http://www.scriptlogic.com/kixtart/FunctionLibrary_ViewFunction.aspx?ID=DateMath
;*** SerialDate http://www.scriptlogic.com/kixtart/FunctionLibrary_ViewFunction.aspx?ID=SerialDate

;NOTE: This script was only tested with KiXtart 4.53 it may work with 4.60 but I have not tested it.

;Set environment variables
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')

;Declare the base registry key and a temp var to suppress values returned to the screen
Dim $BaseKey, $RC
;Set the temp folder location as a global to be available to all scripts
Global $OLTempFolder

$BaseKey = 'HKEY_CURRENT_USER\Software\Microsoft\Office\'

;Depending on what Office version is installed we check the key and location and then
;based upon the returned data we then delete the files based on how many days old they are
;Setting the file delete to 1 or 2 days should be sufficient for most users.
Select
Case KeyExist($BaseKey+'12.0\Outlook\Security')
$OLTempFolder = ReadValue($BaseKey+'12.0\Outlook\Security','OutlookSecureTempFolder')
$RC = ClearOutlookTemp(3)
Case KeyExist($BaseKey+'11.0\Outlook\Security')
$OLTempFolder = ReadValue($BaseKey+'11.0\Outlook\Security','OutlookSecureTempFolder')
$RC = ClearOutlookTemp(3)
Case KeyExist($BaseKey+'10.0\Outlook\Security')
$OLTempFolder = ReadValue($BaseKey+'10.0\Outlook\Security','OutlookSecureTempFolder')
$RC = ClearOutlookTemp(3)
Case KeyExist($BaseKey+'9.0\Outlook\Security')
$OLTempFolder = ReadValue($BaseKey+'9.0\Outlook\Security','OutlookSecureTempFolder')
$RC = ClearOutlookTemp(3)
Case 1
;Unable to locate the folder path so exit the script and set error to 3
$OLTempFolder = ""
Exit 3
EndSelect


;*** REQUIRED UDF SCRIPTS - DO NOT MODIFY THESE SCRIPTS BELOW
;*** These UDF scripts are copied here for ease of scripting only
;*** You may want to verify that you have the latest versions of these UDF scripts
;*** However they have been tested on Server 2003, XP, and Terminal Server 2003 and the script
;*** currently works with the these UDF scripts below.

Function ClearOutlookTemp($Days)
Dim $RC
;The $Days value determines how many days old the file must be before it is deleted
;Checks to ensure that the location of the temporary Outlook files is at least 12 characters
;If you have modified the folder location and it is less, then set the length check to that value
;It is there as a safeguard to prevent deleting files from the root down if the var was blank
If Len($OLTempFolder) >12
$RC = CleanDirectory($OLTempFolder,'*.*',$Days)
EndIf
EndFunction

Function CleanDirectory($directories, $filter, optional $olderas, optional $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($path1, optional $path2)
Dim $a, $path3
$a=UBound($path1)
if $a>0
$path3=$path1[$a]
ReDim Preserve $path1[$a-1]
$path1=fullfile($path1,$path3)
EndIf
If UBound($path1)=0
$path1=$path1[0]
EndIf
If Right($path1,1)='\'
$path1=Left($path1,Len($path1)-1)
EndIf
If $path2
If Left($path2,1)='\'
$path2=Right($path2,Len($path2)-1)
EndIf
$fullfile=LCase($path1+'\'+$path2)
Else
$fullfile=$path1
EndIf
EndFunction

Function DateMath($ExpD1,$ExpD2)
Select
Case InStr($ExpD1,'/') And InStr($ExpD2,'/')
; two date passed - return daysbetween integer
$DateMath=SerialDate($ExpD1)-SerialDate($ExpD2)
If $DateMath<0
$DateMath=$DateMath*-1
EndIf
Case InStr($ExpD1,'/') and 1-InStr($ExpD2,'/')
; date and a number passed - return date
$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,'/') ; date passed
$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
; return an integer
$SerialDate=$d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306
Else ; integer passed
$z=0+$ExpD+306 ; cast numeric
$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)
; return a string date
$SerialDate=''+$y+'/'+$m+'/'+$d
EndIf
EndFunction


.

Top
#188687 - 2008-07-10 11:43 PM Re: Clearout the OutlookSecureTempFolder to prevent Unable to Save File errors [Re: NTDOC]
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
Doc..

Looks like a great script..

I think you can clean up a bit of the script. \:\)

From:
 Code:
Select
  Case KeyExist($BaseKey+'12.0\Outlook\Security')
    $OLTempFolder = ReadValue($BaseKey+'12.0\Outlook\Security','OutlookSecureTempFolder')
    $RC = ClearOutlookTemp(3)
  Case KeyExist($BaseKey+'11.0\Outlook\Security')
    $OLTempFolder = ReadValue($BaseKey+'11.0\Outlook\Security','OutlookSecureTempFolder')
    $RC = ClearOutlookTemp(3)
  Case KeyExist($BaseKey+'10.0\Outlook\Security')
    $OLTempFolder = ReadValue($BaseKey+'10.0\Outlook\Security','OutlookSecureTempFolder')
    $RC = ClearOutlookTemp(3)
  Case KeyExist($BaseKey+'9.0\Outlook\Security')
    $OLTempFolder = ReadValue($BaseKey+'9.0\Outlook\Security','OutlookSecureTempFolder')
    $RC = ClearOutlookTemp(3)
  Case 1
    ;Unable to locate the folder path so exit the script and set error to 3 
    $OLTempFolder = ""
    Exit 3
EndSelect


To:
 Code:
    ; -- Determine version of Outlook
    $exe=ReadValue('HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE','')
    $ver=SPLIT(GetFileVersion($exe),'.')[0]+'.0'
    $OLTempFolder = ReadValue($BaseKey+$ver+'\Outlook\Security','OutlookSecureTempFolder')
    $RC = ClearOutlookTemp(3)


Thanks,

Kent
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#188688 - 2008-07-10 11:51 PM Re: Clearout the OutlookSecureTempFolder to prevent Unable to Save File err [Re: Kdyer]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Thanks Kent,

Yeah it could probably be golfed down and needs to have remote admin ability added as well. If I get time I'll look at your suggestion and the Remote Admin script ability for cleaning remote systems.

Though the remote portion might be a bit more difficult since HKCU can not be read directly.

Top
#188690 - 2008-07-10 11:59 PM Re: Clearout the OutlookSecureTempFolder to prevent Unable to Save File err [Re: NTDOC]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Nice one Doc. Thumbs up for this one.

I see future use for this one (have to get a new job first) to just clear some outlook "junk" at scheduled times as an admin script or a not synch-ed logon script cause otherwise logon might take some time.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#188691 - 2008-07-11 01:56 AM Re: Clearout the OutlookSecureTempFolder to prevent Unable to Save File err [Re: Mart]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
And this isn't in the repository - why??? ;\)

Might be a good exercise to put it there, and then post modifications so new coders can see how a script evolves.

Waddaya think?

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#188692 - 2008-07-11 02:42 AM Re: Clearout the OutlookSecureTempFolder to prevent Unable to Save File err [Re: Glenn Barnas]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Your the only Moderator for that forum so go for it

Group project - best method to support remote admin scripting for this script. I have a few ideas but maybe see what others think.

Top
#188715 - 2008-07-11 11:57 PM Re: Clearout the OutlookSecureTempFolder to prevent Unable to Save File err [Re: NTDOC]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
OK - Leave the original code intact, and I'll collect the ideas, enhancements, and illustrate the process in another article.

Anyone else have ideas or comments to enhance this script?

I'll give it a week or so (depending on activity) and migrate it to the repository.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#188717 - 2008-07-12 01:31 AM Re: Clearout the OutlookSecureTempFolder to prevent Unable to Save File err [Re: Glenn Barnas]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Was thinking a couple of ways of doing the Remote portions.

1. WMI remote execute to read the registry and get the location.
2. Since WMI may not work properly on all systems maybe just do a dir scan for the folders on the system. In all cases I've seen it is always OLK?

Top
#188721 - 2008-07-13 07:59 AM Re: Clearout the OutlookSecureTempFolder to prevent Unable to Save File err [Re: NTDOC]
Kdyer Offline
KiX Supporter
*****

Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
That is the way that I have seen it.

Know what is funny? I don't throw out that much work e-mail. I archive it.. I don't give anybody my work e-mail address unless I am working directly with a client. But, no subscriptions, registrations, etc. Those go my other e-mail addresses.. \:D

Kent


Edited by Kdyer (2008-07-13 08:02 AM)
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 544 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.103 seconds in which 0.069 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org