|
From: Scottmc9 on 23 Jun 2008 13:26 I'm seeking a logon script which will delete the contents of the Recycle Bin. This is necessary because we have found that since we use My Documents folder redirection and Disk Quotas on the Server 2003 R2 SP2 file server, that the Recycle Bin contents on user's computers are being included in Disk Quotas on the server. The script I was using below is causing Windows Script Host vb runtime errors in line 44 'char 4 'Permission Denied' Code 800A0046. Additionally, although this script is the only one I could find via a Web search (I'm not a coder) which actually works on some systems, it appears to be doing more than I need it to do. I would be satisfied if it could simply and effectively empty the Recycle Bin: Option Explicit DIM g_objWshShell, g_objFSO, g_sLogFile, g_objWshNetwork, g_sScriptName, g_sComputerName, g_sUserName Dim g_sVer, g_objLogFile, g_sLogDir 'Setup main variables and objects Set g_objWshShell = WScript.CreateObject("WScript.Shell") 'Create a Shell Object Set g_objFSO = CreateObject("Scripting.FileSystemObject") 'create a File System Object Set g_objWshNetwork = WScript.CreateObject("WScript.Network") 'Create Network Object g_sComputerName = g_objWshNetwork.Computername 'Gets machine Computer name g_sUserName = g_objWshNetwork.UserName 'Gets logged-on username g_sScriptName=UCase(WScript.ScriptName) ' *** Name of the script ' *** START LogFile Information - use Delete or Append info below; don't use both *** Const FORREADING = 1, FORWRITING = 2, FORAPPENDING = 8 'Setup constants for writing, appending, etc g_sLogDir = "C:\TEMP" If Not (g_objFSO.FolderExists(g_sLogDir)) Then g_objFSO.CreateFolder(g_sLogDir) End If g_sLogFile = g_sLogDir & "\" & Left(g_sScriptName,len(g_sScriptName) - 3) & "LOG" 'Makes log file the SCRIPTNAME.Log g_sVer = "1.0" 'To delete a logfile and create a new one each time script is ran If g_objFSO.FileExists(g_sLogFile) Then g_objFSO.DeleteFile(g_sLogFile) 'Delete logfile if it exists. End If Set g_objLogFile = g_objFSO.CreateTextFile(g_sLogFile, FORWRITING) 'Setup the logfile for writing Call Main() Call ExitScript() 'Start main script HERE *** Sub Main() Dim objRecycleBin, objFolderItems, objItem, strSpecialFolderName strSpecialFolderName = "Recycle Bin" 'Call WriteLine("Starting " & g_sScriptName & " at " & Date & " " & Time, g_objLogFile) Set objRecycleBin = GetSpecialFolderObject(strSpecialFolderName) 'Get Special Folder based upon input name Set objFolderItems = objRecycleBin.Items() 'Get items within Recycle Bin For Each objItem In objFolderItems 'Delete all items within Special Folder If (objItem.Type = "File Folder") Then 'Check for file type g_objFSO.DeleteFolder(objItem.Path) 'Delete Folders Else g_objFSO.DeleteFile(objItem.Path) 'Delete Files End If WScript.Echo "Deleted " & objItem.Name Next End Sub '*-*-*-*-*- Start Subroutines here *-*-*-*-*- 'Returns SpecialFolder based upon name of folder 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 'Closes logfile and exits script Sub ExitScript() 'Call WriteLine(Date & " " & Time & "; Completed " & g_sScriptName, g_objLogFile) If IsObject(g_objLogFile) Then g_objLogFile.Close End If Wscript.Quit End Sub Sub EndOnError(sErrorString) WScript.Echo sErrorString & vbcrlf & "Check " & chr(34) & g_sLogFile & Chr(34) & " for details" Call WriteLine (sErrorString, g_objLogFile) WScript.Quit() End Sub 'Shows usage if input is wrong sub ShowUsage() WScript.Echo g_sScriptName & " v" & g_sVer & " Empties Recycle Bin for logged on user" & vbcrlf _ & vbcrlf & "USAGE: [CSCRIPT] " & g_sScriptName WScript.Quit end sub 'Writes to log Sub WriteLine(ByVal strMessage, ByVal objFile) On Error Resume Next If IsObject(objFile) then 'objFile should be a file object objFile.WriteLine strMessage Else Call Wscript.Echo( strMessage ) End If End Sub '*-*-*-*-*- End Subroutines here *-*-*-*-*- '*** End
From: Tom Lavedas on 23 Jun 2008 14:21 On Jun 23, 1:26 pm, Scottmc9 <scott...(a)gmail.com> wrote: > I'm seeking a logon script which will delete the contents of the > Recycle Bin. This is necessary because we have found that since we use > My Documents folder redirection and Disk Quotas on the Server 2003 R2 > SP2 file server, that the Recycle Bin contents on user's computers are > being included in Disk Quotas on the server. The script I was using > below is causing Windows Script Host vb runtime errors in line 44 > 'char 4 'Permission Denied' Code 800A0046. Additionally, although this > script is the only one I could find via a Web search (I'm not a coder) > which actually works on some systems, it appears to be doing more than > I need it to do. I would be satisfied if it could simply and > effectively empty the Recycle Bin: > {snip} I don't know about permissions in a login script, but have a look at this simple approach: http://groups.google.com/group/microsoft.public.scripting.vbscript/msg/9ab4b2f3f6b96cbf Tom Lavedas =========== http://members.cox.net/tglbatch/wsh/
|
Pages: 1 Prev: Object not a Collection Next: <SCRIPT LANGUAGE="VBScript"> and <%%> |