Kaseya Community

Deleting Temp files Script Req.

  • I'm trying to create a Script that deletes Temp files - not files under C:\Temp - no actual user temp files under:

    C:\Documents and Settings\user\Local Settings\Temp


    Or to delete any *.tmp & *.bak files from the system, can we do that.

    Thank you.

    Legacy Forum Name: Deleting Temp files Script Req.,
    Legacy Posted By Username: INFPTN
  • Cleanup.zip
    You'll need to tweak it.

    Mac


    Script Name: 2-1 Maintenance Cycle - Cleanup.exe
    Script Description: Uploads cleanup.exe to the agents temp folder andf runs the program silently with the /autorun switch.

    IF True
    THEN
    Get Variable
    Parameter 1 : 10
    Parameter 2 :
    Parameter 3 : temp
    OS Type : 0
    Write File
    Parameter 1 : C:\temp\Maintcycle\Maintcycle-Cleanup.reg
    Parameter 2 : VSASharedFiles\maintcycle-cleanup.reg
    OS Type : 0
    Execute Shell Command
    Parameter 1 : regedit /s c:\temp\Maintcycle\Maintcycle-Cleanup.reg
    Parameter 2 : 0
    OS Type : 0
    Execute Shell Command
    Parameter 1 : C:\temp\Maintcycle\Cleanup.exe /autorun
    Parameter 2 : 0
    OS Type : 0
    Execute Script
    Parameter 1 : 3-1 Maintenance Cycle Defrag 1- Analyze (NOTE: Script reference is NOT imported. Correct manually in script editor.
    Parameter 2 :
    Parameter 3 : 0
    OS Type : 0
    Write Script Log Entry
    Parameter 1 : maint cycle - Temp files deleted with cleanup.exe
    OS Type : 0
    ELSE

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Mac
  • Thank you so much for your help..

    Should I create a new Script called:"3-1 Maintenance Cycle Defrag 1- Analyze" for the script to execute it?

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: INFPTN
  • You should just delete that part of the script. The script is part of a much larger set of scripts. It just needs to be tweaked for standalone use.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Mac
  • I don't see in the script where Cleanup is uploaded and then installed (hopefully silently).

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: edavis
  • Sorry, I forgot to add that script. This script is part of a larger maintenance cycle script. I would just use this script as an example for building your own. Smile

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Mac
  • It did not work...

    The Script Status: Completed Successfully but none of the files were deleted.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: INFPTN
  • where are the files that you are trying to delete? try this script:

    Script Name: S14 - Run Cleanup.exe
    Script Description: Uploads cleanup.exe to the agents temp folder andf runs the program silently with the /autorun switch.

    IF True
    THEN
    Get Variable
    Parameter 1 : 10
    Parameter 2 :
    Parameter 3 : temp
    OS Type : 0
    Write File
    Parameter 1 : #temp#\Maintcycle-Cleanup.exe
    Parameter 2 : VSASharedFiles\Cleanup.exe
    OS Type : 0
    Write File
    Parameter 1 : #temp#\Maintcycle-Cleanup.reg
    Parameter 2 : VSASharedFiles\maintcycle-cleanup.reg
    OS Type : 0
    Execute Shell Command
    Parameter 1 : regedit /s #temp#\Maintcycle-Cleanup.reg
    Parameter 2 : 0
    OS Type : 0
    Execute Shell Command
    Parameter 1 : #temp#\Maintcycle-Cleanup.exe /autorun
    Parameter 2 : 0
    OS Type : 0
    ELSE

    Try this reg key instead of the other one. Be careful with the scan drive option checked in. I have killed some HP printer software by deleting tmp files.

    Windows Registry Editor Version 5.00

    [HKEY_CURRENT_USER\Software\stevengould.org\CleanUp!\Options]
    "TypeOfCleanUp"="Custom"
    "EmptyRecycleBins"=dword:00000001
    "DeleteNewsgroupCache"=dword:00000001
    "DeleteNewsgroupSubscriptions"=dword:00000001
    "DeleteCookies"=dword:00000000
    "DeletePrefetchFiles"=dword:00000001
    "ScanDrives"=dword:00000000
    "TempFileSpecs"="~*.* *.* ~*.bak *.chk *.tmp"
    "CleanUpAllUsers"=dword:00000001
    "DeleteFavorites"=dword:00000000
    "ResetGameScores"=dword:00000000
    "WipeClean"=dword:00000000
    "EnableSound"=dword:00000000
    "EnableLogFile"=dword:00000001
    "EnableCustomDirs"=dword:00000001
    "CustomDirs"=""
    "EnableCustomRegistry"=dword:00000001
    "CustomRegistry"=""
    "EnableCookieKeeper"=dword:00000001
    "PreserveCookies"=""
    "LogFilename"="C:\\Svit\\Maintcycle\\CleanUp!.log"

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: Mac
  • Does this clean all users or just the currently logged in user?

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: kroberts210
  • AH nevermind, I found my answer in the general options. Thanks for the script.

    Legacy Forum Name: Scripts Forum,
    Legacy Posted By Username: kroberts210
  • When I run the above script on a Windows x64 device, it doesn't write the Cleanup.reg file, but creates "Default" entries, of which one of them is No Log File. If I run "regedit /s #agentTemp#/CleanUp.reg" native on the x64 device, it works fine. Is there an issue running from Kaseya Procedure?

    Thanks!