View Single Post
Old 07-02-2009   #5 (permalink)
Mark D. MacLachlan


 
 

Re: Delete Folders using WMI

Sorry for the repost, but I noticed I had the date checks commented out
on the previously posted version.

Code:
'=======================================================================
===
'
' NAME: CleanHotfixUninstalls.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL   : http://www.thespidersparlor.com
' COPYRIGHT (c) 2008 All rights reserved
' DATE  : 05/07/2008
'
' COMMENT:
'
' This script will enumerate Uninstall folders under the Windows
directory
' and delete them if they are more than two weeks old
'
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE
SUPPLIERS
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'=====================================
Dim fso, WshShell
Dim oFolder, oSubFolder

Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell=CreateObject("WScript.Shell")
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

Path = WinDir

Set oFolder = fso.GetFolder(Path)
Set colSubfolders = oFolder.Subfolders

For Each oSubfolder in colSubfolders
If Left(oSubFolder.Name,1) = "$" Then
If Right(oSubFolder.Name,1) = "$" Then
If DateDiff("d", oSubFolder.DateCreated,Now) > 14 Then
fso.DeleteFolder(oSubFolder)
End If
End If
End If
Next

Set oSubFolder = Nothing
Set oFolder = Nothing
Set fso = Nothing
My System SpecsSystem Spec