Emptying Recycle Bin at Logoff
I remember once having a client who used their *recycle bin* as a bit of a filing system. Anything they didn’t want now, but might need later, they put in there for safe keeping. Safe keeping?!?! Well, we sure can’t let our lusers get away with that - lets teach them the error of their ways. Here is how to force an empty of the recycle bin at logoff via a vb script.
Simply create a GPO that calls the vollowing VB script as part of a “logoff” script, and apply the GPO to all of your users. Easy.
Option Explicit
Dim objWshShell, objFSO, objWshNetwork
Dim objRecycleBin, objFolderItems, objItem, strSpecialFolderName
'Setup main variables and objects
Set objWshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWshNetwork = WScript.CreateObject("WScript.Network")
Set objRecycleBin = GetSpecialFolderObject("Recycle Bin")
Set objFolderItems = objRecycleBin.Items()
For Each objItem In objFolderItems
If (objItem.Type = "File Folder") Then
objFSO.DeleteFolder(objItem.Path)
Else
objFSO.DeleteFile(objItem.Path)
End If
Next
Function GetSpecialFolderObject(NameOfFolder)
Dim objShellApp, i, objSpecialFolder
Set objShellApp = CreateObject("Shell.Application")
On Error Resume Next
For i=0 To 40 '40 is highest value for special folders
Set objSpecialFolder = objShellApp.NameSpace(i)
If (StrComp(objSpecialFolder.Title,NameOfFolder,vbTextCompare)=0) Then
Set GetSpecialFolderObject = objSpecialFolder
Exit For
End If
Next
Err.Clear
End Function
2 Comments
Comments RSS TrackBack Identifier URI
Leave a comment
You must be logged in to post a comment.
Mwa Ha Ha HA haaa! I think I might set this one up at the office just for laughs! Thank you Birdman for helping us to keep the lusers at bay.
BB
*chuckles* Glad I could be of assistance. Stoopid lusers.