Empty Recycle Bin Upon log off

Reading Time: < 1 minute

If you wish to empty a users recycle bin upon log off, copy the below code to a notepad and save with the extension .vsb e.g. clean.vbs

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

Next, add the script to group policy to run when user logs off.

Please carry out tests before applying on the whole network. This was tested on Windows XP

Thanks

Please follow and like us:

2 thoughts on “Empty Recycle Bin Upon log off

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.