Page 1 of 2 12>
Topic Options
#193754 - 2009-05-11 03:10 PM Delete OLK folder
Marjan77 Offline
Fresh Scripter

Registered: 2009-05-11
Posts: 10
Loc: SWEDEN
Hi!
I´m a total beginner at this

I am trying to get the kixscript to delete the OLK folder with the following code:

; ---Tar bort OLK från local settings
 Code:
IF INGROUP ("del_olk")
	MESSAGEBOX (" Test 1", "Test1")
	Del "c:\Documents and Settings\%userprofile%\local settings\Temporary Internet Files\OLK1\*.*"	/s/q
	MESSAGEBOX (" Test 2", "Test2")

ENDIF


I get both messageboxes and no error but the OLK folder is still there.

Anyone got a solution?





Edited by Benny69 (2009-05-12 02:23 PM)
Edit Reason: Added Code Tags

Top
#193755 - 2009-05-11 03:23 PM Re: Delete OLK folder [Re: Marjan77]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Hi and Welcome to the board.

Are you trying to delete the folder or just empty it? The code you posted just empties the OLK1 folder.

Try this and let us know what error you see on the screen.
%userprofile% holds c:\documents and settings\username so in the code you posted you have c:\documents and settings\username\c:\documents and settings\username\local settings\Temporary Internet Files\OLK1\*.*

 Code:
; ---Tar bort OLK från local settings
If InGroup("del_olk")
	MessageBox(" Test 1", "Test1")
	Del %userprofile% + "\local settings\Temporary Internet Files\OLK1\*.*" /s /q
	?"Error code: " @ERROR
	?"Error message: " @SERROR
	MessageBox(" Test 2", "Test2")
EndIf


Edited by Mart (2009-05-11 03:28 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#193756 - 2009-05-11 03:29 PM Re: Delete OLK folder [Re: Marjan77]
BradV Offline
Seasoned Scripter
****

Registered: 2006-08-16
Posts: 687
Loc: Maryland, USA
Try:

 Code:
Dim $USRP
Dim $COMMAND
$USRP=ExpandEnvironmentVars(%userprofile%)
$COMMAND=$USRP + "\local settings\Temporary Internet Files\OLK1\*.*"
Del $COMMAND /s
@ERROR ?



Edited by BradV (2009-05-11 03:49 PM)
Edit Reason: Sorry, was getting mixed up in my scripting languages

Top
#193757 - 2009-05-11 03:32 PM Re: Delete OLK folder [Re: BradV]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
BradV, you might wanna add some $'s in there ;-)
Top
#193758 - 2009-05-11 03:54 PM Re: Delete OLK folder [Re: Mart]
Marjan77 Offline
Fresh Scripter

Registered: 2009-05-11
Posts: 10
Loc: SWEDEN
Hi Mart! and thanks!

I tried your script, I get both messageboxes but no error, and nothing happens to the olk folder.
I would like to delete the OLK folder, in the code I put in before I tried to just delete the content of the folder because I did´n get anything else to work \:\)

The problem with the olk folder is when it fills up, you cant open attached files in outlook until you empty or delete the OLK. Normally outlook deletes this folder but if you open an attachment and close outlook before you close the attachment or OL crashes, OL can no longer delete the folder. Insted OL creates a new folder for ex, OLK1, OLK2 and so on...


Top
#193760 - 2009-05-11 04:10 PM Re: Delete OLK folder [Re: Marjan77]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Ok. For now forget about the messageboxes.
Do you see these lines on your screen?

Error code: SOME ERROR CODE HERE
Error message: SOME TEXT HERE


After you run the script is the fodler empty? If you want to dleet the folder you should use RD and not DEL.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#193761 - 2009-05-11 04:14 PM Re: Delete OLK folder [Re: Mart]
Marjan77 Offline
Fresh Scripter

Registered: 2009-05-11
Posts: 10
Loc: SWEDEN
No, no errorcodes.

And nothing happend to the folder.

Top
#193762 - 2009-05-11 04:16 PM Re: Delete OLK folder [Re: Marjan77]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1896
Loc: Hilversum, The Netherlands
Then it should say:
ERROR: 0
ERROR Message: Completed Successfully

Top
#193764 - 2009-05-11 04:27 PM Re: Delete OLK folder [Re: Arend_]
Marjan77 Offline
Fresh Scripter

Registered: 2009-05-11
Posts: 10
Loc: SWEDEN
I run this:
; ---Tar bort OLK från local settings
 Code:
If InGroup("del_olk")
	MessageBox(" Test 1", "Test1")
	DEL %userprofile% + "\local settings\Temporary Internet Files\OLK1\*.*" /s /q
	?"Error code: " @ERROR
	?"Error message: " @SERROR
	MessageBox(" Test 2", "Test2")
EndIf


Tes1 and Test2 comes up, no error. The OKL folder is still there and all the files to.


Edited by Benny69 (2009-05-12 02:22 PM)
Edit Reason: Added Code Tags

Top
#193765 - 2009-05-11 04:57 PM Re: Delete OLK folder [Re: Marjan77]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Been Googling on this a bit and there are lots of solutions for this.

- Best practice would be to read the path of the OLK folder from the registry because it varies between systems.
- All files in this folder should be gone when outlook exits but when a file is specifically saved there it stays.
- Deleting all files and then deleting the folder would do the trick.
- To prevent outlook nagging about folders and stuff being in use be sure to completely exit Outlook before doing this.

This works for me.
The Sleep 1 is there because without it you might get a timing issue (at least I did).
 Code:
Break on

$folder = ReadValue("HKCU\Software\Microsoft\Office\11.0\Outlook\Security", "OutlookSecureTempFolder")

Del $folder + "\*.*"
Sleep 1
RD $folder
? @ERROR
? @SERROR

Sleep 3


This is for Outlook 2K3. See below for the correct reg key for your outlook/office version.

 Quote:

Outlook 97 - HKEY_CURRENT_USER\Software\Microsoft\Office\8.0\Outlook\Security
Outlook 98 - HKEY_CURRENT_USER\Software\Microsoft\Office\8.5\Outlook\Security
Outlook 2000 - HKEY_CURRENT_USER\Software\Microsoft\Office\9.0\Outlook\Security
Outlook 2002(XP) - HKEY_CURRENT_USER\Software\Microsoft\Office\10.0\Outlook\Security
Outlook 2003 - HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Security
Outlook 2007 - HKEY_CURRENT_USER\Software\Microsoft\Office\12.0\Outlook\Security
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#193766 - 2009-05-11 05:04 PM Re: Delete OLK folder [Re: Mart]
Marjan77 Offline
Fresh Scripter

Registered: 2009-05-11
Posts: 10
Loc: SWEDEN
I´m not sure if I did it right with the "If in group", se below...
But sadly it did not work \:\( The OLK1 folder is still there and its content.


; ---Tar bort OLK från local settings
 Code:
IF INGROUP ("del_olk")
Break on

$folder = ReadValue("HKCU\Software\Microsoft\Office\11.0\Outlook\Security", "OutlookSecureTempFolder")

Del $folder + "\*.*"
Sleep 1
RD $folder
? @ERROR
? @SERROR

Sleep 3
ENDIF


Edited by Benny69 (2009-05-12 02:22 PM)
Edit Reason: Added Code Tags

Top
#193767 - 2009-05-11 05:11 PM Re: Delete OLK folder [Re: Marjan77]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Run my script as it is.
If that works then it's time to add extra stuff like group membership and so on.

I assume you are running office 2003. If not then you should change the registry key to fit your office version like shown in my previous post.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#193769 - 2009-05-11 05:39 PM Re: Delete OLK folder [Re: Mart]
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Here is a script that should clear that folder out for you.

Clearout the OutlookSecureTempFolder to prevent Unable to Save File errors

Top
#193774 - 2009-05-12 09:16 AM Re: Delete OLK folder [Re: NTDOC]
Marjan77 Offline
Fresh Scripter

Registered: 2009-05-11
Posts: 10
Loc: SWEDEN
Hi again!

I tried the last script, sadly nothing happen again.
I put in a couple of messageboxes and I get them but the olk folder ist still there and its content intact.

I checked the registrykey, it was not there so I thought att might pinpoint the olk folder so I put in the path to the olk file in HKEY_CURRENT_USER\Software\Microsoft\Office\11.0\Outlook\Security\OutlookSecureTempFolder

But still the folders content intact. \:\(

Top
#193776 - 2009-05-12 09:23 AM Re: Delete OLK folder [Re: Marjan77]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Then something is wrong with your installation. Outlook creates the folder as soon as it needs it. It is always OLKxxxx where xxxx are one or more numbers. If the registry key for your office/outlook version is not there then outlook did not need an OLK folder yet. The OLK folder you are looking at might be left there for some other reason.

You can test this by opening the parent folder, starting outlook and opening a message with an attachment. The folder should be created as well as the registry key.

- Can you delete the folder manually?
- Does this happen on other machines or is it just your machine?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#193779 - 2009-05-12 09:46 AM Re: Delete OLK folder [Re: Mart]
Marjan77 Offline
Fresh Scripter

Registered: 2009-05-11
Posts: 10
Loc: SWEDEN
This is in our cutomer envirement, on several terminalservers.

I just tried to delet the olk1 that was in my test user, and then logged on again started outlook, opened some attachment and close outlook. A new olk was made, olk8. I login on the TS as admin and checked the registry, no key.

Top
#193783 - 2009-05-12 12:28 PM Re: Delete OLK folder [Re: Marjan77]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
The registry key is created per user. So if test user has a key admin might not have a key for that folder.

If you can delete it manually (when logged on as the user the folder belongs to) but not with a script then some error should come up when running the script.

Can you post the latest version of your script? Because there might have been some changes that are not here.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#193785 - 2009-05-12 01:20 PM Re: Delete OLK folder [Re: Mart]
Marjan77 Offline
Fresh Scripter

Registered: 2009-05-11
Posts: 10
Loc: SWEDEN
Aha okej!
How can I check the rekkey then ??, the user does not have right to run regedit.
This is the latest script i tried.
; ---Tar bort OLK från local settings



 Code:
;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. 

IF INGROUP ("del_olk")
MESSAGEBOX ("NaB Testar 1", "Kärnhem") 
; -- Determine version of Outlook 
Select
  Case KeyExist($BaseKey+'12.0\Outlook\Security')
    $OLTempFolder = ReadValue($BaseKey+'12.0\Outlook\Security','OutlookSecureTempFolder')
    $RC = ClearOutlookTemp(1)
  Case KeyExist($BaseKey+'11.0\Outlook\Security')
    $OLTempFolder = ReadValue($BaseKey+'11.0\Outlook\Security','OutlookSecureTempFolder')
    $RC = ClearOutlookTemp(1)
  Case KeyExist($BaseKey+'10.0\Outlook\Security')
    $OLTempFolder = ReadValue($BaseKey+'10.0\Outlook\Security','OutlookSecureTempFolder')
    $RC = ClearOutlookTemp(1)
  Case KeyExist($BaseKey+'9.0\Outlook\Security')
    $OLTempFolder = ReadValue($BaseKey+'9.0\Outlook\Security','OutlookSecureTempFolder')
    $RC = ClearOutlookTemp(1)
  Case 1
    ;Unable to locate the folder path so exit the script and set error to 3 
    $OLTempFolder = ""
    Exit 3
EndSelect

MESSAGEBOX ("NaB Testar 2", "Kärnhem")


ENDIF

;*** 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






Edited by Benny69 (2009-05-12 02:21 PM)
Edit Reason: Added Code Tags

Top
#193786 - 2009-05-12 02:08 PM Re: Delete OLK folder [Re: Marjan77]
Marjan77 Offline
Fresh Scripter

Registered: 2009-05-11
Posts: 10
Loc: SWEDEN
Hi!!

It´s solved!!
We made a cmd file and set it to run at logoff.

Thanks for the help anyway!!


Edited by Marjan77 (2009-05-12 02:10 PM)

Top
#193787 - 2009-05-12 02:16 PM Re: Delete OLK folder [Re: Marjan77]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Great
So it look like it was some kind of "files in use" issue?
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 2 12>


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

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

Generated in 0.105 seconds in which 0.03 seconds were spent on a total of 14 queries. Zlib compression enabled.

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