Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 10082
  • Last Modified:

Empty Recycle bin on exit using Group Policy

Is it possible to empty a Users Recycle bin automatically when they log off using Group Policy?
0
RobWasho
Asked:
RobWasho
  • 2
2 Solutions
 
AC_NovaCommented:
0
 
RobWashoAuthor Commented:
Thanks for the quick response.  When I run the script I get an error in Line1 Char:28 Error: Expected end of statement code:800A0401

Any ideas?

0
 
AC_NovaCommented:
Download the app, download version 4.71+ of Windows shell.dll.
Check the script for syntax errors.  I have used this before and had no issues.

Hope this helps
0
 
purplepomegraniteCommented:
This VBScript empties the recycle bin, and doesn't require any third party utilities.  Simply add it as a logoff script.
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

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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