<\/use><\/svg><\/div><\/a><\/div><\/p>","upvoteCount":7,"datePublished":"2018-11-13T05:16:56.000Z","url":"https://community.spiceworks.com/t/logoff-script-to-clean-out-temp-files/683503/2","author":{"@type":"Person","name":"brankoceric","url":"https://community.spiceworks.com/u/brankoceric"}},{"@type":"Answer","text":"Hi \nThanks for update<\/p>","upvoteCount":0,"datePublished":"2018-11-13T05:25:20.000Z","url":"https://community.spiceworks.com/t/logoff-script-to-clean-out-temp-files/683503/3","author":{"@type":"Person","name":"spiceuser-ud2np","url":"https://community.spiceworks.com/u/spiceuser-ud2np"}},{"@type":"Answer","text":"
Do you want to clean up user temp folders as well?<\/p>","upvoteCount":0,"datePublished":"2018-11-13T09:32:42.000Z","url":"https://community.spiceworks.com/t/logoff-script-to-clean-out-temp-files/683503/4","author":{"@type":"Person","name":"jrp78","url":"https://community.spiceworks.com/u/jrp78"}},{"@type":"Answer","text":"
Wow. Excellent way to do it. I would never have thought of that way.<\/p>","upvoteCount":0,"datePublished":"2018-11-13T09:33:07.000Z","url":"https://community.spiceworks.com/t/logoff-script-to-clean-out-temp-files/683503/5","author":{"@type":"Person","name":"bbloke","url":"https://community.spiceworks.com/u/bbloke"}},{"@type":"Answer","text":"
I really like Cuber’s method too. \nI’ve been using this script for years. It recurses all the user folders and empties temp folders as well as the Windows temp and if there’s a temp folder on the root. \nYou could edit out the continue prompt and run it on startup or shutdown.<\/p>\n
@echo on\n::@ECHO OFF\n::Tested on 2000/XP/VISTA/Windows 7 only\n\n:WinVersion\ncls\necho ## Definig Windows Version\nver>\"%temp%\\ver.tmp\"\nfind /i \"5.0\" \"%temp%\\ver.tmp\">nul\nif %ERRORLEVEL% EQU 0 set WinVersion=Win2k\nfind /i \"5.1\" \"%temp%\\ver.tmp\">nul\nif %ERRORLEVEL% EQU 0 set WinVersion=WinXP\nfind /i \"5.2\" \"%temp%\\ver.tmp\">nul\nif %ERRORLEVEL% EQU 0 set WinVersion=Win2k3\nfind /i \"6.0\" \"%temp%\\ver.tmp\">nul\nif %ERRORLEVEL% EQU 0 set WinVersion=WinVista/Server2008\nfind /i \"6.1\" \"%temp%\\ver.tmp\">nul\nif %ERRORLEVEL% EQU 0 set WinVersion=Win7/Server2008R2\nif \"%WinVersion%\" EQU \"\" set WinVersion=UNKNOWN\nif %WinVersion% EQU UNKNOWN goto WARN0\nif %WinVersion% EQU WinVista/Server2008 goto WARN1\nif %WinVersion% EQU Win7/Server2008R2 goto WARN1\ngoto START\n\n:START\ncls\ncd %USERPROFILE%\ncd..\nset profiles=%cd%\n\nfor /f \"tokens=* delims= \" %%u in ('dir /b/ad') do (\n\ncls\ntitle Deleting %%u Cookies. . .\nif exist \"%profiles%\\%%u\\cookies\" echo Deleting....\nif exist \"%profiles%\\%%u\\cookies\" cd \"%profiles%\\%%u\\cookies\"\nif exist \"%profiles%\\%%u\\cookies\" del *.* /F /S /Q /A: R /A: H /A: A\n\ncls\ntitle Deleting %%u Temp Files. . .\nif exist \"%profiles%\\%%u\\Local Settings\\Temp\" echo Deleting....\nif exist \"%profiles%\\%%u\\Local Settings\\Temp\" cd \"%profiles%\\%%u\\Local Settings\\Temp\"\nif exist \"%profiles%\\%%u\\Local Settings\\Temp\" del *.* /F /S /Q /A: R /A: H /A: A\nif exist \"%profiles%\\%%u\\Local Settings\\Temp\" rmdir /s /q \"%profiles%\\%%u\\Local Settings\\Temp\"\n\ncls\ntitle Deleting %%u Temp Files. . .\nif exist \"%profiles%\\%%u\\AppData\\Local\\Temp\" echo Deleting....\nif exist \"%profiles%\\%%u\\AppData\\Local\\Temp\" cd \"%profiles%\\%%u\\AppData\\Local\\Temp\"\nif exist \"%profiles%\\%%u\\AppData\\Local\\Temp\" del *.* /F /S /Q /A: R /A: H /A: A\nif exist \"%profiles%\\%%u\\AppData\\Local\\Temp\" rmdir /s /q \"%profiles%\\%%u\\AppData\\Local\\Temp\"\n\ncls\ntitle Deleting %%u Temporary Internet Files. . .\nif exist \"%profiles%\\%%u\\Local Settings\\Temporary Internet Files\" echo Deleting....\nif exist \"%profiles%\\%%u\\Local Settings\\Temporary Internet Files\" cd \"%profiles%\\%%u\\Local Settings\\Temporary Internet Files\"\nif exist \"%profiles%\\%%u\\Local Settings\\Temporary Internet Files\" del *.* /F /S /Q /A: R /A: H /A: A\nif exist \"%profiles%\\%%u\\Local Settings\\Temporary Internet Files\" rmdir /s /q \"%profiles%\\%%u\\Local Settings\\Temporary Internet Files\"\n\ncls\ntitle Deleting %%u Temporary Internet Files. . .\nif exist \"%profiles%\\%%u\\AppData\\Local\\Microsoft\\Windows\\Temporary Internet Files\" echo Deleting....\nif exist \"%profiles%\\%%u\\AppData\\Local\\Microsoft\\Windows\\Temporary Internet Files\" cd \"%profiles%\\%%u\\AppData\\Local\\Microsoft\\Windows\\Temporary Internet Files\"\nif exist \"%profiles%\\%%u\\AppData\\Local\\Microsoft\\Windows\\Temporary Internet Files\" del *.* /F /S /Q /A: R /A: H /A: A\nif exist \"%profiles%\\%%u\\AppData\\Local\\Microsoft\\Windows\\Temporary Internet Files\" rmdir /s /q \"%profiles%\\%%u\\AppData\\Local\\Microsoft\\Windows\\Temporary Internet Files\"\n\n)\n\ncls\ntitle Deleting %Systemroot%\\Temp\nif exist \"%Systemroot%\\Temp\" echo Deleting....\nif exist \"%Systemroot%\\Temp\" cd \"%Systemroot%\\Temp\" \nif exist \"%Systemroot%\\Temp\" del *.* /F /S /Q /A: R /A: H /A: A\nif exist \"%Systemroot%\\Temp\" rmdir /s /q \"%Systemroot%\\Temp\"\n\ncls\ntitle Deleting %SYSTEMDRIVE%\\Temp\nif exist \"%SYSTEMDRIVE%\\Temp\" echo Deleting....\nif exist \"%SYSTEMDRIVE%\\Temp\" cd \"%SYSTEMDRIVE%\\Temp\"\nif exist \"%SYSTEMDRIVE%\\Temp\" del *.* /F /S /Q /A: R /A: H /A: A\nif exist \"%SYSTEMDRIVE%\\Temp\" rmdir /s /q \"%Systemroot%\\Temp\"\n\ncls\ngoto END\n\n:WARN0\ncls\ntitle Warning\necho This program has only been tested for use on:\necho Windows 2000\necho Windows XP\necho Windows Vista\necho Windows 7\necho.\necho Continue at your own risk!\necho.\necho Press 'Y' to continue or any other key to exit.\necho.\nSet /P input=\nif /I %input% EQU Y goto :START\ngoto END\n\n:WARN1\ncls\ntitle Warning\necho For this program to work successfully be sure to\necho Right Click and select\necho Run as Administrator\necho.\necho If you have already done so ignore this warning.\necho.\necho Press 'Y' to continue or any other key to exit.\necho.\nSet /P input=\nif /I %input% EQU Y goto :START\ngoto END\n\n:END\nexit\n\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2018-11-13T12:46:45.000Z","url":"https://community.spiceworks.com/t/logoff-script-to-clean-out-temp-files/683503/6","author":{"@type":"Person","name":"noitforyou","url":"https://community.spiceworks.com/u/noitforyou"}}]}}
How to Clean Temp Files in All Systems whenever they log on to the systems
9 Spice ups
I do it this way (group policy preferences):
7 Spice ups
jrp78
(jrp78)
November 13, 2018, 9:32am
4
Do you want to clean up user temp folders as well?
bbloke
(Chris4738)
November 13, 2018, 9:33am
5
Wow. Excellent way to do it. I would never have thought of that way.
noitforyou
(NoITForYou)
November 13, 2018, 12:46pm
6
I really like Cuber’s method too.
I’ve been using this script for years. It recurses all the user folders and empties temp folders as well as the Windows temp and if there’s a temp folder on the root.
You could edit out the continue prompt and run it on startup or shutdown.
@echo on
::@ECHO OFF
::Tested on 2000/XP/VISTA/Windows 7 only
:WinVersion
cls
echo ## Definig Windows Version
ver>"%temp%\ver.tmp"
find /i "5.0" "%temp%\ver.tmp">nul
if %ERRORLEVEL% EQU 0 set WinVersion=Win2k
find /i "5.1" "%temp%\ver.tmp">nul
if %ERRORLEVEL% EQU 0 set WinVersion=WinXP
find /i "5.2" "%temp%\ver.tmp">nul
if %ERRORLEVEL% EQU 0 set WinVersion=Win2k3
find /i "6.0" "%temp%\ver.tmp">nul
if %ERRORLEVEL% EQU 0 set WinVersion=WinVista/Server2008
find /i "6.1" "%temp%\ver.tmp">nul
if %ERRORLEVEL% EQU 0 set WinVersion=Win7/Server2008R2
if "%WinVersion%" EQU "" set WinVersion=UNKNOWN
if %WinVersion% EQU UNKNOWN goto WARN0
if %WinVersion% EQU WinVista/Server2008 goto WARN1
if %WinVersion% EQU Win7/Server2008R2 goto WARN1
goto START
:START
cls
cd %USERPROFILE%
cd..
set profiles=%cd%
for /f "tokens=* delims= " %%u in ('dir /b/ad') do (
cls
title Deleting %%u Cookies. . .
if exist "%profiles%\%%u\cookies" echo Deleting....
if exist "%profiles%\%%u\cookies" cd "%profiles%\%%u\cookies"
if exist "%profiles%\%%u\cookies" del *.* /F /S /Q /A: R /A: H /A: A
cls
title Deleting %%u Temp Files. . .
if exist "%profiles%\%%u\Local Settings\Temp" echo Deleting....
if exist "%profiles%\%%u\Local Settings\Temp" cd "%profiles%\%%u\Local Settings\Temp"
if exist "%profiles%\%%u\Local Settings\Temp" del *.* /F /S /Q /A: R /A: H /A: A
if exist "%profiles%\%%u\Local Settings\Temp" rmdir /s /q "%profiles%\%%u\Local Settings\Temp"
cls
title Deleting %%u Temp Files. . .
if exist "%profiles%\%%u\AppData\Local\Temp" echo Deleting....
if exist "%profiles%\%%u\AppData\Local\Temp" cd "%profiles%\%%u\AppData\Local\Temp"
if exist "%profiles%\%%u\AppData\Local\Temp" del *.* /F /S /Q /A: R /A: H /A: A
if exist "%profiles%\%%u\AppData\Local\Temp" rmdir /s /q "%profiles%\%%u\AppData\Local\Temp"
cls
title Deleting %%u Temporary Internet Files. . .
if exist "%profiles%\%%u\Local Settings\Temporary Internet Files" echo Deleting....
if exist "%profiles%\%%u\Local Settings\Temporary Internet Files" cd "%profiles%\%%u\Local Settings\Temporary Internet Files"
if exist "%profiles%\%%u\Local Settings\Temporary Internet Files" del *.* /F /S /Q /A: R /A: H /A: A
if exist "%profiles%\%%u\Local Settings\Temporary Internet Files" rmdir /s /q "%profiles%\%%u\Local Settings\Temporary Internet Files"
cls
title Deleting %%u Temporary Internet Files. . .
if exist "%profiles%\%%u\AppData\Local\Microsoft\Windows\Temporary Internet Files" echo Deleting....
if exist "%profiles%\%%u\AppData\Local\Microsoft\Windows\Temporary Internet Files" cd "%profiles%\%%u\AppData\Local\Microsoft\Windows\Temporary Internet Files"
if exist "%profiles%\%%u\AppData\Local\Microsoft\Windows\Temporary Internet Files" del *.* /F /S /Q /A: R /A: H /A: A
if exist "%profiles%\%%u\AppData\Local\Microsoft\Windows\Temporary Internet Files" rmdir /s /q "%profiles%\%%u\AppData\Local\Microsoft\Windows\Temporary Internet Files"
)
cls
title Deleting %Systemroot%\Temp
if exist "%Systemroot%\Temp" echo Deleting....
if exist "%Systemroot%\Temp" cd "%Systemroot%\Temp"
if exist "%Systemroot%\Temp" del *.* /F /S /Q /A: R /A: H /A: A
if exist "%Systemroot%\Temp" rmdir /s /q "%Systemroot%\Temp"
cls
title Deleting %SYSTEMDRIVE%\Temp
if exist "%SYSTEMDRIVE%\Temp" echo Deleting....
if exist "%SYSTEMDRIVE%\Temp" cd "%SYSTEMDRIVE%\Temp"
if exist "%SYSTEMDRIVE%\Temp" del *.* /F /S /Q /A: R /A: H /A: A
if exist "%SYSTEMDRIVE%\Temp" rmdir /s /q "%Systemroot%\Temp"
cls
goto END
:WARN0
cls
title Warning
echo This program has only been tested for use on:
echo Windows 2000
echo Windows XP
echo Windows Vista
echo Windows 7
echo.
echo Continue at your own risk!
echo.
echo Press 'Y' to continue or any other key to exit.
echo.
Set /P input=
if /I %input% EQU Y goto :START
goto END
:WARN1
cls
title Warning
echo For this program to work successfully be sure to
echo Right Click and select
echo Run as Administrator
echo.
echo If you have already done so ignore this warning.
echo.
echo Press 'Y' to continue or any other key to exit.
echo.
Set /P input=
if /I %input% EQU Y goto :START
goto END
:END
exit
1 Spice up