Solved

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

Posted on 2006-07-03
13
8,431 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
  • 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
 
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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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 500 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Resolve Outlook connectivity issues after moving mailbox to new Exchange 2016 server
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now