Kaseya Community

Windows Disk Cleanup (WDC)

  • I just started writing a script that will run the WDC (cleanmgr.exe) application using the /sageset and /sagerun options. I then realized that the deletion of Temp Internet Files will only happen for the user account running the script. How do you handle the cleanup on machines that are accessed by multiple users or for that matter how do you clean the any users Temp Internet files? Need to be able to run the clean overnight and not while a user is logged on.

    I also noticed that the Downloaded program Files folder does not get fully emptied, anyone have any idea why?

    Legacy Forum Name: Windows Disk Cleanup (WDC),
    Legacy Posted By Username: akoop
  • akoop
    I just started writing a script that will run the WDC (cleanmgr.exe) application using the /sageset and /sagerun options. I then realized that the deletion of Temp Internet Files will only happen for the user account running the script. How do you handle the cleanup on machines that are accessed by multiple users or for that matter how do you clean the any users Temp Internet files? Need to be able to run the clean overnight and not while a user is logged on.

    I also noticed that the Downloaded program Files folder does not get fully emptied, anyone have any idea why?


    not sure WHY any of that happens, but i stumbled upon a batch script that went through every profile on a given machine and deleted everything in "local settings\temp" and "local settings\temporary internet files\content.ie5".

    a few major downsides: it's fairly dirty. it only works on the C:, unless you make several versions of the script. and just looking at it now i see a few "goto" problems (no label defined), but it seems to work Big Smile here it is, but i'd test it pretty heavily before you push it out.


    @echo off
    REM - This script searches through each home directory for temporary internet files and deletes them.
    REM - The script also empties the temp folder
    REM - THese lines set the starting directory for the script

    set HDRIVE=C:
    set HPATH=Documents and Settings

    %HDRIVE%
    cd \%HPATH%


    REM - This line sets up the loop for the script
    for /d %%i in (*) do call :ifthen %%i

    goto end

    REM - These lines check for the presence of the temporary internet file directories and call subroutines to deal with them.
    :ifthen
    echo.
    echo.
    echo *** Cleaning files for %1 ...
    if exist "%HDRIVE%\%HPATH%\%1\Local Settings\Temporary Internet Files\Content.IE5" call :ContentDelete1 %1
    if exist "%HDRIVE%\%HPATH%\%1\windows\Temporary Internet Files\Content.IE5" call :ContentDelete2 %1
    if exist "%HDRIVE%\%HPATH%\%1\Local Settings\temp" call :TempDelete %1
    goto :EOF


    REM - This subroutine removes all folders located in the user's "Profile\Local Settings\Temporary Internet Files\Content.IE5"
    REM - directory (in their home directory). It then returns back to the line that it was called from.
    :ContentDelete1

    cd "%HDRIVE%\%HPATH%\%1\Local Settings\Temporary Internet Files\Content.IE5"
    if exist "%HDRIVE%\%HPATH%\%1\Local Settings\Temporary Internet Files\Content.IE5" for /d %%n in (*) do rd /s /q "%%n"
    if exist "%HDRIVE%\%HPATH%\%1\Local Settings\Temporary Internet Files\Content.IE5" del /q "%HDRIVE%\%HPATH%\%1\Local Settings\Temporary Internet Files\Content.IE5\*"
    goto :EOF

    REM - This subroutine removes all folders located in the user's "windows\Temporary Internet Files\Content.IE5" directory located
    REM - in their home directory. It then removes all subfolders from this directory.
    :ContentDelete2
    cd "%HDRIVE%\%HPATH%\%1\windows\Temporary Internet Files\Content.IE5"
    if exist "%HDRIVE%\%HPATH%\%1\windows\Temporary Internet Files\Content.IE5" for /d %%n in (*) do rd /s /q "%%n"
    if exist "%HDRIVE%\%HPATH%\%1\windows\Temporary Internet Files\Content.IE5" del /q "%HDRIVE%\%HPATH%\%1\windows\Temporary Internet Files\Content.IE5\*"

    goto :EOF

    REM - This subroutine removes all folders located in the user's "windows\Temporary Internet Files\Content.IE5" directory located
    REM - in their home directory. It then removes all subfolders from this directory.
    :TempDelete
    cd "%HDRIVE%\%HPATH%\%1\Local Settings\Temp"
    if exist "%HDRIVE%\%HPATH%\%1\Local Settings\Temp" for /d %%n in (*) do rd /s /q "%%n"
    if exist "%HDRIVE%\%HPATH%\%1\Local Settings\Temp" del /q "%HDRIVE%\%HPATH%\%1\Local Settings\Temp\*"

    goto :EOF

    :end



    I've used it on terminal servers without problems. works wonders, really. obviously needs to be revised. if anyone makes any worthwhile improvements, post it here so i can nab it!

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: seb
  • Is an utility called ICSweep that we run on client terminal servers. It cleans Temp IE files and Temp folders of ALL users.

    Google the utility, softpedia has a download.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: JonJohnston
  • This batch file really work like champ for only XXX\temp folder. Did you get some ways or modifications done to it for cleaning xxxx\Temporary Internet Files folder too.

    Please post if you had

    Thanks
    Rajeev

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: rajeevsharma
  • drivefreespace.zip
    Drivefreespace.exe is an autoIT script to give free space of the system drive in % free. Run this first, create a script log, run the VBS clean up script. Then run the drivefreespace again to see the results before and after. Create report and pull from script log. I also set this up to run automatically if a machine reports it is low on space.

    Script Name: Delete Temp Files
    Script Description:

    IF Test File
    Parameter 1 : C:\temp\deltemp.vbs
    Exists :
    THEN
    Execute File
    Parameter 1 : C:\temp\drivefreespace.exe
    Parameter 2 :
    Parameter 3 : 1
    OS Type : 0
    Get Variable
    Parameter 1 : 1
    Parameter 2 : C:\temp\drivefreespace.txt
    Parameter 3 : FreeSpaceBefore
    OS Type : 0
    Execute File
    Parameter 1 : %SYSTEMROOT%\SYSTEM32\WSCRIPT.EXE
    Parameter 2 : C:\temp\deltemp.vbs
    Parameter 3 : 3
    OS Type : 0
    Execute File
    Parameter 1 : C:\temp\drivefreespace.exe
    Parameter 2 :
    Parameter 3 : 1
    OS Type : 0
    Get Variable
    Parameter 1 : 1
    Parameter 2 : C:\temp\drivefreespace.txt
    Parameter 3 : FreeSpaceAfter
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : FreeSpace Before: #FreeSpaceBefore#
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : FreeSpace After: #FreeSpaceAfter#
    OS Type : 0
    Delete File
    Parameter 1 : C:\temp\deltemp.vbs
    OS Type : 0
    ELSE
    Write File
    Parameter 1 : C:\temp\deltemp.vbs
    Parameter 2 : VSASharedFiles\deltemp.vbs
    OS Type : 0
    Write File
    Parameter 1 : C:\temp\drivefreespace.exe
    Parameter 2 : VSASharedFiles\drivefreespace.exe
    OS Type : 0
    Execute Script
    Parameter 1 : Delete Temp Files (NOTE: Script reference is NOT imported. Correct manually in script editor.
    Parameter 2 : 1
    Parameter 3 : 1
    OS Type : 0

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: brotharewt