Kaseya Community

Disk Clean up

This question is not answered

So I'm looking for a script that can clean up alllll the junk on a persons computer. Currently I've discovered this one but it seems to only deal with a small portion of the crap that accumulates on computers...

Remove-Item (@(“C:\Windows\Temp\*”, “C:\Windows\Prefetch\*”, “C:\Documents and Settings\*\Local Settings\temp\*”, “C:\Users\*\Appdata\Local\Temp\*”)) -force -recurse

It doesn't do anything with Windows updates, recycling bin, internet temp files, etc.. I would really love to be able to silently automate disk clean up but I can't figure out a way for that. We only manage Windows 7 and 10 machines so I need something that will work for both OS. Any suggestions people??

I've found a lot of discussions about this but they all seem to be pretty outdated by years.

All Replies
  • The maintenance pack in our RMM Suite include a disk cleanup tool that cleans the following by default:

    TEMP folders

     %SystemDrive%\tmp

     %SystemDrive%\temp

     %SystemRoot%\temp

     D:\temp

    User Folders:

     \Local Settings\temp

     \Local Settings\Temporary Internet Files\Content.IE5

     \Local Settings\History\History.IE5

    Hotfix Folders

     %SystemRoot%\$*Uninstall*$

     %SystemRoot%\*.log

     %SystemRoot%\Prefetch

     %SystemRoot%\Logs\CBS

    Folders that don't exist are ignored, and the Default and All Users folders are not processed when scanning for User temp folders.

    Additional folders can be defined via a configuration file that allows global, per client, per machine-group, or per-agent configuration settings. Only files not in active use and more than a specific (default 5) number of days old are touched. Every eligible file is logged with the action (delete or ignore). A FORCE argument overrides the default aging value and uses "1 day" for extreme cleanup. Hotfix folders have a separate aging value of 90 days to support diagnostic and removal actions.

    This is executed daily by the maintenance system. Smart Monitors that check disk capacity can invoke this tool directly as a self-remediation process when the calculated low-space threshold is first crossed. This action often eliminates low disk space alerts entirely.

    The tool works on all current Windows server and workstation platforms and has been tested on Windows 2000 (yes, 2000!) and above.

    There is a companion tool to this that specifically performs log maintenance - has the ability to recycle apps/services, archive logs over a certain age, move logs to a central repository, and maintain local copies for a specific time (natively or in a ZIP archive).

    This is one of seven regular maintenance tools that we offer, and we run them daily on 3000+ endpoints in our MSP practice. This regular maintenance has significantly reduced both alerts and customer calls due to common but often overlooked maintenance tasks.

    Glenn

  • In my experience similar to what @gbarnas is alluding to; creating an efficient and powerful cleanup procedure will likely call other procedures within a master procedure.

    My first suggestion would be to map everything you would like reviewed and cleaned from the endpoint.  This serves as the basis to R&D and automate.

  • Create an efficient cleanup procedure will call other procedures within a master procedure.



    -
    [edited by: Jenny Escobar at 8:10 AM (GMT -7) on May 8, 2018]
  • Here is our cleanup VBS script run weekly as part of weekly maintenance routines.  A combination of several 3rd parties and personal methods over the years.  Your mileage may vary.

    _____________

    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

    f.WriteLine ""

    strValueName = "ProfileImagePath"

    strSubPath = strKeyPath & "\" & objSubkey

    objRegistry.GetExpandedStringValue HKEY_LOCAL_MACHINE,strSubPath,strValueName,sProfile

    f.WriteLine "Cleaning profile folder " & profileCount & " of " & profileQty & " : " & sProfile

    DeleteFolderContents sProfile & "\Local Settings\Temp"

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

    If objFSO.FolderExists(sProfile & "\AppData\Local") Then

    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\Temp"

    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

    objWSH.Run "icacls " & sProfile & "\Appdata\Local\Temp\Low /setintegritylevel low", 0

        End If

    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

  • I also looking for something that can clean junk files but don't know how to use those scripts.

    doge 2048



    correction
    [edited by: estell2 at 4:31 AM (GMT -7) on Sep 20, 2018]