Help creating batch file that will delete all user profile temp files on logoff.
Hi folks. I want to put a batch file together that will delete all files at the user profile in the following directories when my users log off:
C:\Users\USER\AppData\Local\Temp
C:\Users\USER\AppData\Local\Microsoft\Windows\Temporary Internet Files
C:\Windows\Temp
Help would be appreciated! Thanks.
October 21st, 2010 10:48am
I have one that cleans different temp folders in windows.. like CCleaner but for all users.
not sure if it only works in XP, but it should be easy to modify if so.. you could run it in sheduled tasks (taskschd.msc)
@echo off
SET SRC1=C:\Documents and Settings
SET SRC2=Local Settings\Temporary Internet Files\Content.IE5
SET SRC3=Local Settings\History
SET SRC4=Local Settings\Temp
SET SRC5=Cookies
echo cleaning temporary internet files
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
echo cleaning history
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR /S /Q "%%Y"
echo cleaning windows temp files
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC4%\*.*") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"
echo cleaning Cookies
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC5%\*.*") DO DEL /F /S /Q "%%Y"
del /f /s /q "%windir%\temp"
FOR /D %%X IN ("%windir%\temp\*") DO RMDIR /S /Q "%%X"
Free Windows Admin Tool Kit Click here and download it now
October 21st, 2010 2:31pm
I have one that cleans different temp folders in windows.. like CCleaner but for all users.
not sure if it only works in XP, but it should be easy to modify if so.. you could run it in sheduled tasks (taskschd.msc)
@echo off
SET SRC1=C:\Documents and Settings
SET SRC2=Local Settings\Temporary Internet Files\Content.IE5
SET SRC3=Local Settings\History
SET SRC4=Local Settings\Temp
SET SRC5=Cookies
echo cleaning temporary internet files
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC2%\*.*") DO RMDIR /S /Q "%%Y"
echo cleaning history
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC3%\*.*") DO RMDIR /S /Q "%%Y"
echo cleaning windows temp files
FOR /D %%X IN ("%SRC1%\*") DO FOR /D %%Y IN ("%%X\%SRC4%\*.*") DO RMDIR /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC3%\*.*") DO DEL /F /S /Q "%%Y"
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC4%\*.*") DO DEL /F /S /Q "%%Y"
echo cleaning Cookies
FOR /D %%X IN ("%SRC1%\*") DO FOR %%Y IN ("%%X\%SRC5%\*.*") DO DEL /F /S /Q "%%Y"
del /f /s /q "%windir%\temp"
FOR /D %%X IN ("%windir%\temp\*") DO RMDIR /S /Q "%%X"
WOW. Does it really have to be that complicated? Can't it be done using the del command?
October 21st, 2010 3:21pm
A simple del command line may not work, because you do not have access on the temp files of other users. If you still encounter problems after trying this suggestion, I recommend that you discuss it in our Script Center, you may need a VB script that can
ignore UAC.
The Official Scripting Guys Forum!
Arthur Xie
TechNet Subscriber Support in forum
If you have any feedback on our support, please contact
tngfb@microsoft.com.Please remember to click Mark as Answer on the post that helps you, and to click Unmark as Answer if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Free Windows Admin Tool Kit Click here and download it now
October 22nd, 2010 2:39am
Thank you so much! It works for me. :)
December 1st, 2010 7:20am