Kaseya Community

Kaseya Procedure to Delete Windows Temp Files

This question is answered

I have been trying to create a script to delete these files and subfolders for a long time now.   The Files/Subfolders I am speaking of are located in C:\Windows\Temp\.

I was able to create a VBScript very simply to delete these files but the locked files will not delete, even though I am logged in as full admin.  I have procedures to run disk cleanup and ICSweep as well as CCleaner but none of these delete the files I need.


Here is my VERY simple vbs:

/////////////////////////////////////////////////////////////////////

Const DeleteReadOnly = TRUE

Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("C:\Windows\Temp\*"), DeleteReadOnly
objFSO.DeleteFolder("C:\Windows\Temp\*"),DeleteReadOnly

/////////////////////////////////////////////////////////////////////

When I run this I get the following error:

Permission Denied:  800A0046 Microsoft VBScript error

Can anyone help me out here?  Maybe I am just missing a simple item.  Also, I need this script/procedure to be silent so we do not interrupt user workflow.

Thanks! Big Smile

Verified Answer
  • Clear_ALL_Folders.zip

    I accomplish this using a combination of a vbs script and a few lines of scripting in Kaseya.

    I have attached the vbs and the script I made in Kaseya.

    The Kaseya script is also clearing IE folders.

All Replies
  • We use an app we developed to perform folder cleanups - has a list of standard locations and additional folders can be defined when needed. It removes files only after a specific time (3 or 5 days usually, but can be set to 0 days for a FORCED cleanup). Extensive logging reports every file/path that's been removed, and it removes its own logs after a week. Reports the space reclaimed after cleanup as well.

    As for the KWorking folder, we never use it for temporary storage - a bad idea in my opinion. We have a BIN folder with some support tools (and add it to the system PATH variable) and a Logs folder for logs written by our maintenance suite and support utilities.These are retained for only 1 week.

    Every one of our procedures that pushes files out for installation identifies the System drive, checks it for the Temp folder, creating it if necessary, and then creates an app subfolder under Temp. All files are copied there, and the installer executed from that location, with logs written to that folder as well. Logs, if created, are uploaded to Kaseya, and the Temp\app folder is recursively deleted, cleaning up after the process. Nothing is left behind that can be used inappropriately, and nothing is left in the KWorking folder.

    Glenn

  • Hello All-

    I have been testing this script and was finally able to run it successfully after creating the folder and subfolder under the kworking directory on a test machine and adding the .log files.

    I create the log files in notepad using the .LOG as the first line and using the naming convention as noted in the procedure script.  When i receive the email notification, the disk before and after fields are blank and my log file created an odd numberic sequence to detail the disk space of the drive.

    Can someone detail how they configured the .log files so i can get the right info from the procedure?



    updated the post to indicate the change as need different help
    [edited by: mikey090tx at 5:58 AM (GMT -8) on Dec 6, 2018]
  • Function ForceCScript()
    On Error Resume Next
    WScript.StdErr.Write(Chr(7))
    If Err.Number <> 0 Then
    Err.Clear
    On Error GoTo 0
    set WshSh=WScript.CreateObject("WScript.Shell")
    sh=WshSh.ExpandEnvironmentStrings("%COMSPEC%")
    If InStr(sh,"%") = 1 Then sh="cmd.exe"
    WshSh.Run(sh&" /K cscript /nologo """&WScript.ScriptFullName&"""")
    WScript.Quit()
    End If
    End Function

    call ForceCScript()

    dim objWSH, objFSO, sysDrv
    dim initialFreeSpace
    dim strComputer
    dim objRegistry
    dim strKeyPath, objSubKey, arrSubkeys, strValueName
    dim sProfile
    dim sTemp, sTmp, sWindows, sLocalAppData, sProgramData, sWER, sDotNetItem
    dim profileQty, profileCount
    Dim fso
    Set fso = WScript.CreateObject("Scripting.Filesystemobject")
    Set f = fso.CreateTextFile("C:\ktemp\spyware\MTSCate.2.0.log", 2)

    f.WriteLine "CleanAllTemp"
    f.WriteLine ""
    f.WriteLine "Cleans all profiles' temp and IE cache folders"
    f.WriteLine "A whole subfolder deletion is indicated by \"
    f.WriteLine "A file deletion is indicated by ,"
    f.WriteLine "A whole subfolder deletion failure is indicated by X"
    f.WriteLine "A file deletion failure is indicated by x"

    wscript.echo "Clean All Temp Etc."
    wscript.echo "Please wait while we search, process and remove all temp files..."
    wscript.echo ""

    set objFSO = CreateObject("Scripting.FileSystemObject")
    set objWSH = CreateObject("WScript.Shell")
    set sysDrv = objFSO.GetDrive(objFSO.GetDriveName(objWSH.ExpandEnvironmentStrings("%SystemDrive%")))
    'set sa = CreateObject("Shell.Application")
    'Set items = sa.Namespace(10).Items()


    sTemp = objWSH.ExpandEnvironmentStrings("%TEMP%")
    sTmp = objWSH.ExpandEnvironmentStrings("%TMP%")
    sWindows = objWSH.ExpandEnvironmentStrings("%SystemRoot%")
    sLocalAppData = objWSH.ExpandEnvironmentStrings("%LOCALAPPDATA%")
    sProgramData = objWSH.ExpandEnvironmentStrings("%ProgramData%")
    If sProgramData <> "" Then
    sWER = objWSH.ExpandEnvironmentStrings("%ProgramData%") & "\Microsoft\Windows\WER\ReportQueue"
    Else
    sWER = ""
    End If

    ' Get current free space on system drive
    initialFreeSpace = CDbl(sysDrv.FreeSpace)

    Const HKEY_LOCAL_MACHINE = &H80000002

    strComputer = "."

    Set objRegistry=GetObject("winmgmts:\\" & _
    strComputer & "\root\default:StdRegProv")

    strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
    objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubkeys
    profileQty = uBound(arrSubkeys) + 1
    profileCount = 1

    For Each objSubkey In arrSubkeys

    strValueName = "ProfileImagePath"
    strSubPath = strKeyPath & "\" & objSubkey
    objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,sProfile

    wscript.echo "Cleaning profile folder " & profileCount & " of " & profileQty & " : " & sProfile

    DeleteFolderContents sProfile & "\Local Settings\Temp"

    DeleteFolderContents sProfile & "\Local Settings\Temporary Internet Files"

    DeleteFolderContents sProfile & "\AppData\Local\Google\Chrome\User Data\Default\Cache"
    DeleteFolderContents sProfile & "\AppData\Local\Google\Chrome\User Data\Default\JumpListIconsOld"
    DeleteFolderContents sProfile & "\AppData\Local\Google\Chrome\User Data\Default\JumpListIcons"
    DeleteFolderContents sProfile & "\AppData\Local\Google\Chrome\User Data\Default\Local Storage"
    DeleteFolderContents sProfile & "\AppData\Local\Google\Chrome\User Data\Default\Media Cache"
    DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\WebCach"
    DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\Temporary Internet Files"
    'DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\INetCache"
    DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\Explorer"
    DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Terminal Server Client\Cache"
    DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Internet Explorer\Recovery"

    ' Windows 8 and 8.1
    'DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\INetCache\IE"

    ' Windows 10
    DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\INetCache\Low\Content.IE5"
    DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\INetCache\Low\Flash"
    DeleteFolderContents sProfile & "\AppData\Local\Microsoft\Windows\INetCache\Content.Outlook"

    If objFSO.FolderExists(sProfile & "\AppData\Local\Temp") Then
    DeleteFolderContents sProfile & "\AppData\Local\Temp"
    If Not objFSO.FolderExists(sProfile & "\AppData\Local\Temp\Low") Then
    objFSO.CreateFolder(sProfile & "\AppData\Local\Temp\Low")
    End If
    If Not objFSO.FolderExists(sProfile & "\AppData\Local\Temp\1") Then
    objFSO.CreateFolder(sProfile & "\AppData\Local\Temp\1")
    End If
    objWSH.Run "icacls " & sProfile & "\Appdata\Local\Temp\Low /setintegritylevel low", 0
    objWSH.Run "icacls " & sProfile & "\Appdata\Local\Temp\1 /setintegritylevel low", 0
    End If

    DeleteFolderContents sProfile & "\Application Data\Local\Microsoft\Windows\WER"

    DeleteFolderContents sProfile & "\Application Data\Adobe\Flash Player\AssetCache"

    DeleteFolderContents sProfile & "\Application Data\Sun\Java\Deployment\cache"

    DeleteFolderContents sProfile & "\Application Data\Microsoft\CryptnetUrlCache"

    profileCount = profileCount + 1

    Next

    ' Now empty certain folders in %SystemRoot%
    f.WriteLine
    f.WriteLine "Processing folder: " & sWindows & "\Logs\CBS"

    Dim objWMIService1, objService1
    Dim strService1,strComputer1
    strService1="TrustedInstaller"
    strComputer1 = "."
    Set objWMIService1 = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer1 & "\root\cimv2")
    For Each objService1 In objWMIService1.ExecQuery("Select * from Win32_Service Where Name = '"_
    &strService1&"'")
    objService1.StopService
    Next

    KillProc "TrustedInstaller.exe"

    f.WriteLine
    f.WriteLine "Processing folder: " & sWindows & "\Temp"
    DeleteFolderContents sWindows & "\Temp"
    f.WriteLine ""

    f.WriteLine "Processing folder: " & sWindows & "\system32\wbem\Logs"
    DeleteFolderContents sWindows & "\system32\wbem\Logs"
    f.WriteLine ""

    f.WriteLine "Processing folder: " & sWindows & "\Debug"
    DeleteFolderContents sWindows & "\Debug"
    f.WriteLine ""

    f.WriteLine "Processing folder: " & sWindows & "\PCHEALTH\ERRORREP\UserDumps"
    DeleteFolderContents sWindows & "\PCHEALTH\ERRORREP\UserDumps"
    f.WriteLine ""

    ' And ditto the system-wide Windows Error Reporting queue, if it exists.
    If sWER <> "" Then
    f.WriteLine "Processing folder: " & sWER
    DeleteFolderContents sWER
    End If
    f.WriteLine ""

    ' Delete all log files.
    '''f.WriteLine "Processing folder: " & sWindows & "\system32\Logfiles"
    'DeleteSubfolderFiles sWindows & "\system32\Logfiles"
    'f.WriteLine ""

    ' Delete all *.pf in Prefetch
    f.WriteLine "Deleting " & sWindows & "\Prefetch\*.pf"
    objWsh.run "CMD.EXE /C DEL """ & sWindows & "\Prefetch\*.pf"" > NUL", 0, true
    f.WriteLine ""

    ' Delete all temp.txt in syswow64
    f.WriteLine "Deleting " & sWindows & "\syswow64\temp.txt"
    objWsh.run "CMD.EXE /C DEL """ & sWindows & "\syswow64\temp.txt"" > NUL", 0, true
    f.WriteLine ""

    ' Delete all temp.txt in system32
    f.WriteLine "Deleting " & sWindows & "\system32\temp.txt"
    objWsh.run "CMD.EXE /C DEL """ & sWindows & "\system32\temp.txt"" > NUL", 0, true
    f.WriteLine ""

    ' Delete Trash Bin
    f.WriteLine "Deleting " & sysDrv & "\$Recycle.Bin"
    objWsh.run "CMD.EXE /C rd /s /q """ & sysDrv & "\Recycler"" > NUL", 0, true
    objWsh.run "CMD.EXE /C DEL """ & sysDrv & "\$Recycle.Bin"" > NUL", 0, true
    f.WriteLine ""

    ' Avoid crashing if elevation is needed to delete a file.
    On Error Resume Next
    For Each item in items
    If objFSO.FileExists(item.Path) Then
    objFSO.DeleteFile item.Path, True
    Else
    objFSO.DeleteFolder item.Path, True
    End If
    Next

    'Start Trusted Installer Services
    'Dim objWMIService2, objService2
    'Dim strService2,strComputer2
    'strService2="Windows Modules Installer"
    'strComputer2 = "."
    'Set objWMIService2 = GetObject("winmgmts:" _
    ' & "{impersonationLevel=impersonate}!\\" & strComputer2 & "\root\cimv2")
    'For Each objService2 In objWMIService2.ExecQuery("Select * from Win32_Service Where Name = '"_
    '&strService2&"'")
    ' objService2.StartService
    'Next

    f.WriteLine "Running the Advanced Windows Disk Cleanup Utility "
    'Option Explicit
    On Error Resume Next

    Dim WshShell

    Set WshShell=CreateObject("WScript.Shell")

    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Active Setup Temp Folders\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Setup Files\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Downloaded Program Files\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Files\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Memory Dump Files\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Content Indexer Cleaner\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\GameNewsFiles\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\GameStatisticsFiles\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Internet Cache Files\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Offline Pages Files\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Previous Installations\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Recycle Bin\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Service Pack Cleanup\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Temporary Sync Files\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Thumbnail Cache\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Upgrade Discarded Files\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting Archive Files\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting Queue Files\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting System Archive Files\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Error Reporting System Queue Files\StateFlags0001","2","REG_DWORD"
    WshShell.RegWrite "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\Windows Upgrade Log Files\StateFlags0001","2","REG_DWORD"

    SetRegKeys
    DoCleanup

    Sub DoCleanup()
    WshShell.Run "C:\WINDOWS\SYSTEM32\cleanmgr /sagerun:1"
    End Sub

    Sub SetRegKeys
    Dim strKeyPath
    Dim strComputer
    Dim objReg
    Dim arrSubKeys
    Dim SubKey
    Dim strValueName
    Const HKLM=&H80000002

    strKeyPath="SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches"
    strComputer="."
    strValueName="StateFlags0001"

    Set objReg=GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
    objReg.Enumkey HKLM ,strKeyPath,arrSubKeys

    For Each SubKey In arrSubKeys

    objReg.SetDWORDValue HKLM,strKeyPath & "\" & SubKey,strValueName,2

    Next

    End Sub

    WaitForProcess ".", "cleanmgr.exe"

    f.WriteLine ""
    f.WriteLine "Freed " & CLng( CDbl(CDbl(sysDrv.FreeSpace) - CDbl(initialFreeSpace))/CDbl(1024*1024)) & " megabytes."
    Write.echo "Freed " & CLng( CDbl(CDbl(sysDrv.FreeSpace) - CDbl(initialFreeSpace))/CDbl(1024*1024)) & " megabytes."

    f.WriteLine ""

    f.WriteLine "Cleanup has been completed. Review log file in Kaseya Agent Documents folder MTSCate.2.0.log for details."
    wscript.echo "Cleanup has been completed. Review log file in Kaseya Agent Documents folder MTSCate.2.0.log for details."

    Set sysDrv = Nothing
    Set objWsH = Nothing
    Set objFSO = Nothing
    Set objRegistry = Nothing

    f.Close
    'End of Script


    ' ---------------------- Subroutines -------------------

    Sub WaitForProcess(strComputer, strProcess)
    Dim wmiQuery : wmiQuery = "Select * From Win32_Process Where Name='" _
    & strProcess & "'"
    Dim objWMIService : Set objWMIService = GetObject("winmgmts:\\" & strComputer _
    & "\root\cimv2")
    Dim colItems : Set colItems = objWMIService.ExecQuery(wmiQuery)

    Dim intProcCount : intProcCount = colItems.Count
    Do While intProcCount > 0
    Set colItems = objWMIService.ExecQuery(wmiQuery)
    intProcCount = colItems.Count
    WScript.Sleep 1000
    Loop
    End Sub

    sub DeleteFolderContents(strFolder)
    ' Deletes all files and folders within the given folder
    dim objFolder, objFile, objSubFolder, doCRLF
    on error resume next

    ' Just exit if the named folder doesn't exist on this system
    If Not objFSO.FolderExists(strFolder) Then
    Exit Sub
    End If

    doCRLF = 0
    set objFolder=objFSO.GetFolder(strFolder)

    if Err.Number<>0 then
    Err.Clear
    set objFolder = Nothing
    Exit Sub ' Couldn't get a handle to the folder, so can't do anything
    end if
    for each objSubFolder in objFolder.SubFolders
    objSubFolder.Delete true
    if Err.Number<>0 then
    'Could not delete whole folder
    f.Write "X"
    'Try recursive, delete everything inside,
    'ensuring as complete an overall result as possible
    'do NOT do CRLF after this sub iteration ends
    doCRLF = 0
    Err.Clear
    DeleteFolderContents(strFolder & "\" & objSubFolder.Name)
    else
    f.Write "\"
    doCRLF = 0
    end if
    next
    for each objFile in ObjFolder.Files
    objFile.Delete true
    if Err.Number<>0 then
    f.Write "x"
    doCRLF = 0
    Err.Clear ' In case we couldn't delete a file
    else
    f.Write ","
    doCRLF = 0
    end if
    next

    Set objFolder = Nothing
    'if doCRLF > 0 then
    'f.WriteLine vbCRLF
    'end if
    end sub

    sub DeleteSubfolderFiles(strFolder)
    ' Deletes all files only, within subfolders of the current folder
    dim objFolder, objFile, objSubFolder, doCRLF
    on error resume next

    doCRLF = 0

    set objFolder=objFSO.GetFolder(strFolder)

    if Err.Number<>0 then
    Err.Clear
    set objFolder = Nothing
    Exit Sub ' Couldn't get a handle to the folder, so can't do anything
    end if

    for each objSubFolder in objFolder.SubFolders
    for each objFile in objSubFolder.Files
    objFile.Delete true
    if Err.Number<>0 then
    f.Write "x"
    doCRLF = 0
    Err.Clear ' In case we couldn't delete a file
    else
    f.Write ","
    doCRLF = 0
    end if
    next
    next

    Set objFolder = Nothing

    if doCRLF > 0 then
    f.write vbCRLF
    end if
    end sub

    sub force_cscript
    dim args : args=""
    dim i, wshshell
    If right(lCase(wscript.fullname),11)= "wscript.exe" then
    for i=0 to wscript.arguments.count-1
    args = args & wscript.arguments(i) & " "
    next

    Set WshShell = CreateObject("wscript.shell")

    wshshell.run wshshell.ExpandEnvironmentStrings("%comspec%") & _
    " /k Title Clean All Temp Etc. v4.10 |MODE 90,30 | color 0e &cscript.exe //nologo """ _
    & wscript.scriptfullname & """" & args

    set wshshell=nothing

    wscript.quit
    end if
    end sub

    Sub KillProc( myProcess )
    'Purpose: Kills a process and waits until it is truly dead

    Dim blnRunning, colProcesses, objProcess
    blnRunning = False


    Set colProcesses = GetObject( _
    "winmgmts:{impersonationLevel=impersonate}" _
    ).ExecQuery( "Select * From Win32_Process", , 48 )
    For Each objProcess in colProcesses
    If LCase( myProcess ) = LCase( objProcess.Name ) Then
    ' Confirm that the process was actually running
    blnRunning = True
    ' Get exact case for the actual process name
    myProcess = objProcess.Name
    ' Kill all instances of the process
    objProcess.Terminate()
    End If
    Next

    If blnRunning Then
    ' Wait and make sure the process is terminated.
    f.WriteLine myProcess & " process is running and is being terminated. Please wait..."
    Do Until Not blnRunning
    Set colProcesses = GetObject( _
    "winmgmts:{impersonationLevel=impersonate}" _
    ).ExecQuery( "Select * From Win32_Process Where Name = '" _
    & myProcess & "'" )
    WScript.Sleep 100 'Wait for 100 MilliSeconds
    If colProcesses.Count = 0 Then 'If no more processes are running, exit loop
    blnRunning = False
    End If
    Loop
    ' Display a message
    f.WriteLine ""
    f.WriteLine myProcess & " was terminated"
    f.WriteLine ""
    f.WriteLine "Deleting contents of CBS Log Files"
    f.WriteLine ""
    DeleteFolderContents sWindows & "\Logs\CBS"
    Else
    f.WriteLine "Process """ & myProcess & """ process not found"
    f.WriteLine ""
    f.WriteLine "Deleting contents of CBS Log Files"
    DeleteFolderContents sWindows & "\Logs\CBS"
    f.WriteLine ""
    End If
    End Sub

  • CleanAllTemp

    Cleans all profiles' temp and IE cache folders
    A whole subfolder deletion is indicated by \
    A file deletion is indicated by ,
    A whole subfolder deletion failure is indicated by X
    A file deletion failure is indicated by x
    \,\\\\\\,\\Xx\\Xx\\Xx\\\\\\\\\\\\\,,,,,,,,xXxxxxx,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,xXxxxxxxxxxxxxx\\\\x,,,,,,x\\Xx\\Xx
    Processing folder: C:\Windows\Logs\CBS
    Process "TrustedInstaller.exe" process not found

    Deleting contents of CBS Log Files
    ,

    Processing folder: C:\Windows\Temp
    \\\x,,,,,,,,,,,,,,xx
    Processing folder: C:\Windows\system32\wbem\Logs

    Processing folder: C:\Windows\Debug
    xx
    Processing folder: C:\Windows\PCHEALTH\ERRORREP\UserDumps

    Processing folder: C:\ProgramData\Microsoft\Windows\WER\ReportQueue

    Deleting C:\Windows\Prefetch\*.pf

    Deleting C:\Windows\syswow64\temp.txt

    Deleting C:\Windows\system32\temp.txt

    Deleting C:\$Recycle.Bin

    Running the Advanced Windows Disk Cleanup Utility

    Freed 2279 megabytes.

    Cleanup has been completed. Review log file in Kaseya Agent Documents folder MTSCate.2.0.log for details.