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 'Load ASDK namespaces set nsAgent = CreateObject("Altiris.AeXNSClient") set psAgent = nsAgent.ClientPolicyMgr.ClientAgent( "Altiris.AeXNSCPkgSvr" ) '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 clientPoliciesPath = path & "\Client Policies" path = path & "\Package Delivery" end if strLogfile = "\CAHSnapshotRefresh.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 fs.FileExists(item.Path & "\snapshot.xml") Then foo = foo +1 logFile.WriteLine("Deleting " & item.Path & " (" & item.Size & " bytes)") Wscript.Echo "Deleting " & item.Path & "\snapshot.xml" fs.DeleteFile item.Path & "\snapshot.xml", force End If Next 'Delete the client policies (will recreate during client configuration) WScript.Echo "Deleting Client Policies (*.xml) from " & clientPoliciesPath fs.DeleteFile clientPoliciesPath & "\*.xml", force 'Quick pause then update client configuration WScript.Echo "Getting ready to update client configuration..." WScript.Sleep(1000) ignoreBlockouts = 1 call nsAgent.UpdatePolicies(ignoreBlockouts) Wscript.Echo "Updated client configuration." 'Another (longer) pause so client config can get to the machine before we refresh packages Wscript.Echo "Getting ready to refresh packages..." WScript.Sleep(10000) psagent.RefreshPackages() Wscript.Echo "Package refresh started." logFile.WriteLine(foo & " Snapshots Deleted") logFile.WriteLine("End Execution on " & Date & " at " & Time) logFile.WriteLine("----------") logFile.Close wscript.echo "Snapshots Deleted: " & foo 'Kill the objects because we're done Set folder = Nothing set fs = Nothing set logFile = Nothing