• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8457
  • Last Modified:

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

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
kapara
Asked:
kapara
  • 7
  • 6
1 Solution
 
bruintjeCommented:
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
 
kaparaAuthor Commented:
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
 
bruintjeCommented:
yes i think so, it would be good to always test on a normal account first before rolling out
0
Easily manage email signatures in Office 365

Managing email signatures in Office 365 can be a challenging task if you don't have the right tool. CodeTwo Email Signatures for Office 365 will help you implement a unified email signature look, no matter what email client is used by users. Test it for free!

 
kaparaAuthor Commented:
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
 
bruintjeCommented:
no problem, you mean run it on original and network folder?
0
 
kaparaAuthor Commented:
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
 
bruintjeCommented:
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
 
kaparaAuthor Commented:
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
 
kaparaAuthor Commented:
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
 
bruintjeCommented:
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
 
kaparaAuthor Commented:
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
 
bruintjeCommented:
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
 
kaparaAuthor Commented:
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 7
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now