Recycle Bin ~ VBScript




Tagged Under : , ,

Version: 13.4
Revision: 34 Build 65

Recycle Bin ~ VBScript

Introduction: this little Script will deletes files and folders permanently as they just bypass Recycle Bin completely…

The recycle bin saves all the files or folders, which have been removed by the user after using them. So, it gets piled up and degrade your computer performances! These files and folders can also be restored back, if required at later stage. Sooner or later, it must also be cleared otherwise space problem will added. This setting just bypasses recycle bin. Therefore, it remains clear (always), even if required very urgently later, can not be restored back!

1.] Download notepad++ from the original author or from a mirror and install the software.
——————————-

http://sourceforge.net/projects/notepad-plus/

http://filehippo.com/download_notepad/

——————————-

Disable ~ NoRecycleFiles
—Copy Source Code—

Author: Lair360
'Version: 16.2
'Revision: 35 Build 16
'-------------------------------------------
On Error Resume Next
Dim nret1,nret2
'-------------------------------------------
Wscript.Echo "This script will 'DISABLE' NoRecycleFiles..."
'--------------------------------------------
'Don't modify any of these strings!
'Any modification to this line is very risky...
'--------------------------------------------
Set globaldrive=WScript.CreateObject("WScript.Shell")
nret1=globaldrive.Run("cmd /C reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\ /v NoRecycleFiles /t REG_DWORD /d 0 /f",0,TRUE)
nret2=globaldrive.Run("cmd /C reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer\ /v NoRecycleFiles /t REG_DWORD /d 0 /f",0,TRUE)
'-------------------------------------------
WScript.Echo "Please reboot your computer or log off..."
'VBScript Ends

—End Source Code—

Enable ~ NoRecycleFiles
—Copy Source Code—

'Author: Lair360
'Version: 16.2
'Revision: 35 Build 16
'-------------------------------------------
On Error Resume Next
Dim nret1,nret2
'-------------------------------------------
Wscript.Echo "This script will 'Enable' NoRecycleFiles..."
'--------------------------------------------
'Don't modify any of these strings!
'Any modification to this line is very risky...
'--------------------------------------------
Set globaldrive=WScript.CreateObject("WScript.Shell")
nret1=globaldrive.Run("cmd /C reg add HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\ /v NoRecycleFiles /t REG_DWORD /d 1 /f",0,TRUE)
nret2=globaldrive.Run("cmd /C reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\Explorer\ /v NoRecycleFiles /t REG_DWORD /d 1 /f",0,TRUE)
'-------------------------------------------
WScript.Echo "Please reboot your computer or log off..."
'VBScript Ends

—End Source Code—
Copyright 2001-2008 Lair360




Clear Recycle Bin VBScript




Tagged Under : , ,

Version: 35
Revision: 46 Build 178

Clear Recycle Bin

Introductions: This VBScript enable users to delete everything from their recycle bin -regardless of their situation. This script will also help you to clear large amount of stuff from your recycle bin without losing your precious time.

Clear Recycle Bin version 1
—Copy Source Code—

'************************************************
' Project: EmptyRecycleBinv1.vbs
' Author:  Lair360
' Version: 2.1
'************************************************
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("Shell.Application")
Set oFolder = oFSO.GetFolder("C:\RECYCLER")
If (Not oFolder Is Nothing) Then
For Each oFldr In oFolder.SubFolders
Set oNS = oShell.NameSpace(oFldr.Path)
If (Not oFolder Is Nothing) Then
oNS.Self.InvokeVerb("Empty Recycle &Bin")
Set oNS = Nothing
Exit For
End If
Next
Set oFolder = Nothing
End if
Set oFSO = Nothing
Set oShell = Nothing

—End Source Code—

Clear Recycle Bin version 2
—Copy Source Code—

'************************************************
' Project: EmptyRecycleBinv2.vbs
' Author:  Lair360
' Version: 2.3
'************************************************
Set oWSH = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Function ScriptPath
ScriptPath = oFSO.GetParentFolderName(WScript.ScriptFullName) & "\"
End Function
Sub Sleep(x)
Start = cint(second(time))
i = 0
Do
i = i + 1
Loop While cint(second(time)) < Start + cint(x)
End Sub
Set fEBin = oFSO.CreateTextFile(ScriptPath & "Tmp_EBin.vbs",2)
fEBin.writeline "Set oFSO = CreateObject(""Scripting.FileSystemObject"")"
fEBin.writeline "Set oShell = CreateObject(""Shell.Application"")"
fEBin.writeline "Set oFolder = oFSO.GetFolder(""C:\RECYCLER"")"
fEBin.writeline "If (Not oFolder Is Nothing) Then"
fEBin.writeline "     For Each oFldr In oFolder.SubFolders"
fEBin.writeline "    Set oNS = oShell.NameSpace(oFldr.Path)"
fEBin.writeline "    If (Not oFolder Is Nothing) Then"
fEBin.writeline "        oNS.Self.InvokeVerb(""Empty Recycle &Bin"")"
fEBin.writeline "        Set oNS = Nothing"
fEBin.writeline "        Exit For"
fEBin.writeline "    End If"
fEBin.writeline "  Next"
fEBin.writeline "  Set oFolder = Nothing"
fEBin.writeline "End if"
fEBin.writeline "Set oFSO = Nothing"
fEBin.writeline "Set oShell = Nothing"
fEBin.close
iReturn = oWSH.Run ("""" & ScriptPath & "Tmp_EBin.vbs""", 0, False)
Sleep 2
'MsgBox iReturn
iReturn = oWSH.AppActivate("Confirm Multiple File Delete")
'MsgBox iReturn
If iReturn = "False" Then iReturn = oWSH.AppActivate("Confirm File Delete")
If iReturn = "True" Then oWSH.SendKeys("{ENTER}")
'* Delete temp file
oFSO.DeleteFile ScriptPath & "Tmp_EBin.vbs"
Set oWSH = Nothing
Set oFSO = Nothing

—End Source Code—

Clear Recycle Bin version: 3
—Copy Source Code—

'************************************************
' Project: EmptyRecycleBinv3.vbs
' Author:  Lair360
' Version: 3.2
'************************************************
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, objects and computer name
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 ***
'Setup constants for writing, appending and etc
Const FORREADING = 1, FORWRITING = 2, FORAPPENDING = 8
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
Next

End Sub
'Returns SpecialFolders 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 of VBScript…

—End Source Code—
Copyright 2001-2008 Lair360