?
Solved

URGENT!!! Delete OLK files on close of outlook...different directory

Posted on 2006-07-03
13
Medium Priority
?
8,451 Views
Last Modified: 2011-08-18
I posted a question about how to delete temp files which Outlook leaves behind in the OLK directories.  For security purposes we would like to redirect them to a network drive and then have the script delete those files from that network drive.  If someone could modify the script so that the script looks in the following place:  U:\OLK.

Private Sub Application_Quit()
    Dim objFSO As Object, _
        objTempFilesFolder As Object, _
        objFolder As Object, _
        strProfilePath As String
    strProfilePath = Environ("USERPROFILE")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTempFilesFolder = objFSO.GetFolder(strProfilePath & "\Local Settings\Temporary Internet Files")
    For Each objFolder In objTempFilesFolder.SubFolders
        If Left(objFolder.Name, 3) = "OLK" Then
            objFSO.DeleteFile objFolder.Path & "\*.*", True
        End If
    Next
    Set objFolder = Nothing
    Set objTempFilesFolder = Nothing
    Set objFSO = Nothing
End Sub
0
Comment
Question by:kapara
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 17032792
Hi kapara,
----------

you refer to this question
http://www.experts-exchange.com/Applications/MS_Office/Outlook/Q_21892912.html

however i do not know for sure if you can run a script to delete files in a network folder the user account the script is running under should have read/write/delete access to the folder i assume

then it would become something like

Private Sub Application_Quit()
    Dim objFSO As Object, _
        objTempFilesFolder As Object, _
        strProfilePath As String
    strStoragePath = "U:\OLK"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTempFilesFolder = objFSO.GetFolder(strStoragePath)
    objFSO.DeleteFile objTempFilesFolder.Path & "\*.*", True
    Set objTempFilesFolder = Nothing
    Set objFSO = Nothing
End Sub

----------
bruintje
share what you know, learn what you don't
0
 
LVL 1

Author Comment

by:kapara
ID: 17032830
The U:\ Drive is their User folder assigned in their profile so the User has full control of the folder.  Since they have full control they should be able to do so correct?

Thanks
0
 
LVL 44

Expert Comment

by:bruintje
ID: 17032915
yes i think so, it would be good to always test on a normal account first before rolling out
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:kapara
ID: 17032952
Is there a way to run both scripts?  I would also like to remove any pevious temp files.  If you feel that it should be asked as another question since it is slightly different then the original...I can.


Thanks
0
 
LVL 44

Expert Comment

by:bruintje
ID: 17032966
no problem, you mean run it on original and network folder?
0
 
LVL 1

Author Comment

by:kapara
ID: 17032969
It works on the U:\ drive.  I just hope there is a way to run both so I can remove the old data and then the new.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 17032988
that would be something like

Private Sub Application_Quit()
    Dim objFSO As Object, _
        objTempFilesFolder As Object, _
        objFolder As Object, _
        strProfilePath As String
        strStoragePath As String
   
    ' delete temporary files on local machine
    strProfilePath = Environ("USERPROFILE")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTempFilesFolder = objFSO.GetFolder(strProfilePath & "\Local Settings\Temporary Internet Files")
    For Each objFolder In objTempFilesFolder.SubFolders
        If Left(objFolder.Name, 3) = "OLK" Then
            objFSO.DeleteFile objFolder.Path & "\*.*", True
        End If
    Next
   
    ' delete temporary files on network machine
    strStoragePath = "U:\OLK"
    Set objTempFilesFolder = objFSO.GetFolder(strStoragePath)
    objFSO.DeleteFile objTempFilesFolder.Path & "\*.*", True
   
   
    Set objFolder = Nothing
    Set objTempFilesFolder = Nothing
    Set objFSO = Nothing
End Sub
0
 
LVL 1

Author Comment

by:kapara
ID: 17032996
Yes...because I do not want to have to go to each machine and run the script.  I am going to add the VBA project via CMW  Office customization which will add the script and I will also add the change for the OLK location by adding a reg file to this CMW file.  Then users execute the shortcut I email them and voila!
0
 
LVL 1

Author Comment

by:kapara
ID: 17033035
I get a compile error:  Statement invalid Outside Type Block

This is where:  

Private Sub Application_Quit()
    Dim objFSO As Object, _
        objTempFilesFolder As Object, _
        objFolder As Object, _
        strProfilePath As String
        strStoragePath As String <--------------Error causes running script to stop here.
   
    ' delete temporary files on local machine
    strProfilePath = Environ("USERPROFILE")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTempFilesFolder = objFSO.GetFolder(strProfilePath & "\Local Settings\Temporary Internet Files")
    For Each objFolder In objTempFilesFolder.SubFolders
        If Left(objFolder.Name, 3) = "OLK" Then
            objFSO.DeleteFile objFolder.Path & "\*.*", True
        End If
    Next
   
    ' delete temporary files on network machine
    strStoragePath = "U:\OLK"
    Set objTempFilesFolder = objFSO.GetFolder(strStoragePath)
    objFSO.DeleteFile objTempFilesFolder.Path & "\*.*", True
   
   
    Set objFolder = Nothing
    Set objTempFilesFolder = Nothing
    Set objFSO = Nothing
End Sub
0
 
LVL 44

Accepted Solution

by:
bruintje earned 2000 total points
ID: 17033044
sorry

Private Sub Application_Quit()
    Dim objFSO As Object, _
        objTempFilesFolder As Object, _
        objFolder As Object, _
        strProfilePath As String, _
        strStoragePath As String
   
    ' delete temporary files on local machine
    strProfilePath = Environ("USERPROFILE")
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTempFilesFolder = objFSO.GetFolder(strProfilePath & "\Local Settings\Temporary Internet Files")
    For Each objFolder In objTempFilesFolder.SubFolders
        If Left(objFolder.Name, 3) = "OLK" Then
            objFSO.DeleteFile objFolder.Path & "\*.*", True
        End If
    Next
   
    ' delete temporary files on network machine
    strStoragePath = "U:\OLK"
    Set objTempFilesFolder = objFSO.GetFolder(strStoragePath)
    objFSO.DeleteFile objTempFilesFolder.Path & "\*.*", True
   
   
    Set objFolder = Nothing
    Set objTempFilesFolder = Nothing
    Set objFSO = Nothing
End Sub
0
 
LVL 1

Author Comment

by:kapara
ID: 17034445
Works great!  What I am doing now is I use selfcert.exe to create a certificate and attach it to the VB Macro.  I then export it to a .CER file.  I modify the reg entry pointing Outlook Temp files to go to each users Personal Folder and export that to a .reg file..  I create a CMW file with the Custom Maintenance Wizard and add the 2 objects.  I can then add it to a logon script or execute it at each machine.  The vb and cert are automatically added to the Trusted Publishers and no more work is needed.
0
 
LVL 44

Expert Comment

by:bruintje
ID: 17034630
that sounds really great, i didn't know you could use a selfcert on other users pc thats new for me :)

thanks for the grade
0
 
LVL 1

Author Comment

by:kapara
ID: 17034917
I also added the vbproject.otm to the Application/Microsoft/Outlook through the Custom Maintenance Wizard.  You still have to manually install the Cert for some reason.  This just means viewing it installing it in the default locations and then enable and always trust the source.  Might be easier to use a local Certificate Authority, but at least there is a way to distribute the VBproject.otm.
0

Featured Post

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Mailbox Overload?
Changing a few Outlook Options can help keep you organized!
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question