Link to home
Start Free TrialLog in
Avatar of kapara
kapara

asked on

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
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Hi kapara,
----------

you refer to this question
https://www.experts-exchange.com/questions/21892912/How-to-prevent-Outlook-temp-files-from-staying-in-OLK-directories.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
Avatar of kapara
kapara

ASKER

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
yes i think so, it would be good to always test on a normal account first before rolling out
Avatar of kapara

ASKER

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
no problem, you mean run it on original and network folder?
Avatar of kapara

ASKER

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.
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
Avatar of kapara

ASKER

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!
Avatar of kapara

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of Brian Mulder
Brian Mulder
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kapara

ASKER

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.
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
Avatar of kapara

ASKER

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.