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.Fi leSystemOb ject")
Set objTempFilesFolder = objFSO.GetFolder(strProfil ePath & "\Local Settings\Temporary Internet Files")
For Each objFolder In objTempFilesFolder.SubFold ers
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
Private Sub Application_Quit()
Dim objFSO As Object, _
objTempFilesFolder As Object, _
objFolder As Object, _
strProfilePath As String
strProfilePath = Environ("USERPROFILE")
Set objFSO = CreateObject("Scripting.Fi
Set objTempFilesFolder = objFSO.GetFolder(strProfil
For Each objFolder In objTempFilesFolder.SubFold
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
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
Thanks
yes i think so, it would be good to always test on a normal account first before rolling out
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
Thanks
no problem, you mean run it on original and network folder?
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.Fi leSystemOb ject")
Set objTempFilesFolder = objFSO.GetFolder(strProfil ePath & "\Local Settings\Temporary Internet Files")
For Each objFolder In objTempFilesFolder.SubFold ers
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(strStorag ePath)
objFSO.DeleteFile objTempFilesFolder.Path & "\*.*", True
Set objFolder = Nothing
Set objTempFilesFolder = Nothing
Set objFSO = Nothing
End Sub
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.Fi
Set objTempFilesFolder = objFSO.GetFolder(strProfil
For Each objFolder In objTempFilesFolder.SubFold
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(strStorag
objFSO.DeleteFile objTempFilesFolder.Path & "\*.*", True
Set objFolder = Nothing
Set objTempFilesFolder = Nothing
Set objFSO = Nothing
End Sub
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!
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.Fi leSystemOb ject")
Set objTempFilesFolder = objFSO.GetFolder(strProfil ePath & "\Local Settings\Temporary Internet Files")
For Each objFolder In objTempFilesFolder.SubFold ers
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(strStorag ePath)
objFSO.DeleteFile objTempFilesFolder.Path & "\*.*", True
Set objFolder = Nothing
Set objTempFilesFolder = Nothing
Set objFSO = Nothing
End Sub
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.Fi
Set objTempFilesFolder = objFSO.GetFolder(strProfil
For Each objFolder In objTempFilesFolder.SubFold
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(strStorag
objFSO.DeleteFile objTempFilesFolder.Path & "\*.*", True
Set objFolder = Nothing
Set objTempFilesFolder = Nothing
Set objFSO = Nothing
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
thanks for the grade
ASKER
I also added the vbproject.otm to the Application/Microsoft/Outl ook 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.
----------
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.Fi
Set objTempFilesFolder = objFSO.GetFolder(strStorag
objFSO.DeleteFile objTempFilesFolder.Path & "\*.*", True
Set objTempFilesFolder = Nothing
Set objFSO = Nothing
End Sub
----------
bruintje
share what you know, learn what you don't