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
  • Curtis,  

    Not a direct answer, but an option.  You mention you tried CCleaner, was it the "free" version?   I believe their Business Edition has some advantages including multi-profile cleaning (not just the active user) and "advanced lock detection".. but whether that translates to deleting them I am not sure.  They have a Kaseya integration with a free trial, www.greaterintell.com/CCleaner.html might be worth a try.  

  • 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.

  • I am running this now.  It did a good job at clearing what I wanted so that's a GREAT start.  However, it is loud to the user as in it has to run prompts on the screen.  Is there any way for the internet temp files to be deleted silently?

  • I have not looked into trying to make that part silent since I run this as part of a new agent install and during troubleshooting a system it has not been an issue for me. I am not sure if it would be possible to make silent at least not using the steps I am using right now.

  • Okay jmaque, looks really good but I changed 2 things and added a third.  You were deleting c:\temp, not just the contents either, so I changed that a bit since a lot users have data in the folder that really isn't temp (shame on them).  I also changed the procedure to, at the end, delete the .vbs from c:.  Lastly, we have had a lot of issues with C:\Windows\Logs\CBS filling up.  I added the command to delete this as well.  In all, this solved my issue! THANKS!

  • Glad my script fit your needs.. I cant  take complete credit for it though as the vbs is NOT mine. Original author is credited in the vbs, I simply modified a few liens in the vbs. I will be adding the CBS logs to my script though, as i just checked a couple of machines of mine and each had at least 1GB of logs.

  • Can you please post your updated script? Thanks!

  • Procedure Clear ALL temp folders.xml

    Not sure if you meant my updated script or, but my updated script is attached.

  • Clear ALL temp folders Loud.xml

    Attached XML File updated

    I attached the vbs as well as a txt.  I removed the del c:/temp as it could cause issues

    3343.deleteTempFiles.txt

    let me know if there are any questions.

  • Hello,

    When I try to import I get this error:

    The file you are trying to import is not formatted correctly. It contains invalid XML.

    Wally

  • Procedure Disk Cleanup.xml

    I have a kaseya script that runs only kaseya code that cleans up the following folders/files older than 15 days, and empties the trash. Additional folder paths can be easily added. On average this script clears 10+gb

    C:\Users\Administrator\AppData\Local\Temp\
    C:\windows\temp\
    C:\windows\Logs\CBS\
    C:\Windows\SoftwareDistribution\Download\
    C:\Users\Administrator\AppData\Local\Microsoft\Windows\Temporary Internet Files\content.ie5\
    C:\Users\Administrator\AppData\Local\Microsoft\Windows\Temporary Internet Files\
    C:\ProgramData\Microsoft\Windows\WER\ReportQueue\

  • Hello Everyone,

    Would it not be easier as below?

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

    You can run this with a one Execute Powershell step in Kaseya.

    You can add folders as needed (adding prefetch for example is easy)

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

    And it would delete the temp from every profile in the machine.

    Best Regards

  • I really like this script in the option to send email after procedure runs, since i have a 3rd party that needs to know hard drive space after script runs. However I am receiving the following error when running. "FAILED in processing THEN step 53, Get Variable, with error File Open Failed, Get content from file c:\kworking\scripts\win_logs\DiskB4.log (Line 61)"

    Thanks in advance for any help

  • Lane,

    2 things to check:

    - Make sure the folder structure exists

      c:\kworking\scripts\win_logs\

    - Make sure the file is created on the system

      diskb4.log

  • Thank you. It worked like a charm. The folder structure was not the same. I modified the procedure to match directory structure.

    Curious though how and why you create your folder structure as you do. I basically just have the kworking folder and it does get quite cluttered