function readFromRegistry (strRegistryKey, strDefault ) Dim WSHShell, value On Error Resume Next Set WSHShell = CreateObject("WScript.Shell") value = WSHShell.RegRead( strRegistryKey ) if err.number <> 0 then readFromRegistry= strDefault else readFromRegistry=value end if set WSHShell = nothing end function 'Grab the Package Server Path from the registry. If not found, the script should quit path = readFromRegistry("HKEY_LOCAL_MACHINE\SOFTWARE\Altiris\Altiris Agent\Package Server\PackageServerBaseDir","NA") if path = "NA" then 'Registry key not found -- this may not be a package server WScript.Quit(1) else 'Key found, append the Package Delivery folder to the path path = path & "\Package Delivery" end if strLogfile = "\CAHPackageCleanup.log" Const ForAppending = 8 set objFS = CreateObject("Scripting.FileSystemObject") set logFile = objFS.OpenTextFile(path & strLogfile, ForAppending, True) logFile.WriteLine("----------") logFile.WriteLine("Begin Execution on " & Date & " at " & Time) set fs = CreateObject("Scripting.FileSystemObject") set folder = fs.GetFolder(path) For each item in folder.SubFolders 'snapshot.xml is missing from that folder, so delete the folder If Not fs.FileExists(item.Path & "\snapshot.xml") Then foo = foo +1 bar = bar + item.Size logFile.WriteLine("Deleting " & item.Path & " (" & item.Size & " bytes)") Wscript.Echo "Deleting " & item.Path fs.DeleteFolder item.Path, force End If Next logFile.WriteLine(foo & " Packages Deleted") logFile.WriteLine(bar & " Bytes Deleted") logFile.WriteLine("End Execution on " & Date & " at " & Time) logFile.WriteLine("----------") logFile.Close wscript.echo "Packages Deleted: " & foo wscript.echo "Disk Space Freed: " & bar 'Kill the objects because we're done Set folder = Nothing set fs = Nothing set logFile = Nothing