Kaseya Community

Delete Temp Files only works on XP Machines

This question has suggested answer(s)

Current script does

If true

   getVariable(Agent Install Drive (C:\)", " ", "drv", "All Operating Systems", "Halt on Fail")

   executeShellCommand(del #drv#temp\*.* /q", "Execute as User", "All Windows Operating Systems", "Halt on Fail")

This reports as successful on Windows 7 32-bit and 64-bit, but doesn't actually delete any files.

There is a Windows Environmental "TEMP" variable that is defined as %USERPROFILE%\AppData\Local\Temp.

%USERPROFILE% on Windows 7 evaluates in our shop to c:\users\username.ourdomain

How can I modify this procedure to work with these conditions.  I'm NOT interested in the CCleaner scripts that many have mentioned as we don't have CCleaner installed on all machines and don't particularly want it installed.

Does anyone have any help that directly addresses this question???


All Replies
  • Are you running the script as the user, or system?

    win7 has two temp folders - c:\windows\temp and c:\users\%username%\appdata\local\temp - which are you trying to clean??

    p.s. ccleaner portable is the way to go; you can push it from the VSAshared files folder to your agent folder, run t, then remove it when you're done (or just leave it for next time) - no need to install permanently on machines.

  • Have you tested portable ccleaner on win2003/win2008/win7/Winxp !!

    does not seem to do always the job due to 32 & 64 bit systems and their differences

  • There are several ways available to do this via Agent Procedures.  The absolute simplest would be to just execute a shell command as SYSTEM and use the same command you would use from the command prompt:

    del /s /f %TEMP%

    del /s /f %WINDIR%\temp

    We had added at one time this line as well:

    del /s /f #vAgentConfiguration.AgentTempDir#\*

    But this may not work for everybody.  Depends on what you are doing with Kaseya.

    Personally, I would use the Delete Directory step in Agent Procedures.  Execute Shell Command is a wonderful step, but it fires blind.  It is "successful" so long as the command was sent successfully, not if the command *executed* successfully.  So I try to avoid using it when I can with Kaseya scripts.

    Delete Directory is very useful however.  Simply add the step, enter in the path or environmental variable of the path into the appropriate field and make sure you check "Recursively delete sub-directories and files" and you are done.  Couldn't be simpler.

    Made suggested answer.
    [edited by: Peter at 11:22 AM (GMT -7) on Jul 1, 2013]
  • Not sure if this will make any difference but you are missing a '\' in your step

    del #drv#temp\*.*       You have no '\ after #drv# variable so change it to

    del #drv#\temp\*.*