Question Locked

Deleting -all- temp / internet files for -all- users on a pc, automatically

0 helpful
8 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Am looking for a way to delete the files stored in multiple users' temp folders and internet cache folders. All of our PCs are on a domain, and users move about frequently.

Leads to about 1/2 dozen login info on each PC. Our industry is very info-sensitive, so deleting the user account is not a option (if they stored files on their desktop).

Diskclean is good, but far from perfect. Anyone have a script to go into:

C:\Documents and Settings\USERNAME\Local Settings\temporary internet files

and

C:\Documents and Settings\USERNAME\Local Settings\temp

for -each- user? Thanks in advance.

8 replies

by bizzo

This isn't a complete script, but it will get a list of the users' directories in c:\documents and settings

@echo off
for /f "tokens=*" %%I in ('dir /ad /b "c:\documents and settings\*.*"') do (
echo "c:\documents and settings\%%I\Local Settings\temporary internet files"
echo "c:\Documents and Settings\%%I\Local Settings\temp"
)

by jruby

Try something like this:

Cleanup the temporary internet files by deleting and recreating the directory:

------------------------------------
cd "C:\Documents and Settings"
rem step through all directories here
FOR /D %%F in (*.*) DO (
rem move into the user's local settings
PUSHD "%%F\Local Settings"
rem if temporary internet files exists
rem remove it and all sub directories,
rem the /q (quiet) switch avoids prompts
IF EXIST "Temporary Internet Files" (rd/s/q "Temporary Internet Files")
rem create a new, empty directory
md "Temporary Internet Files"
rem pop back up to the documents and settings directory
rem and go to the next user.
POPD
)
------------------------------------

Clean up the temp directories
(Some description omitted here because it's already in the above script)
------------------------------------

cd "C:\Documents and Settings"
FOR /D %%F in (*.*) DO (
PUSHD "%%F\Local Settings\Temp"
rem delete all the files in this dir
DEL /Q *.*
rem delete all subdirectories in this dir
FOR /D %%D in (*.*) DO RD /S /Q %%D
POPD
)
------------------------------------

Please, PLEASE, PULEEEZE test these thoroughly on a recoverable system - these work on my systems but you may have to make adjustments for your environment. The DEL/Q and RD/S/Q are VERY dangerous (more dangerous than "FORMAT C:" dangerous because you don't get a confirmation prompt before things are wiped out).

You can leave off the /Q on all the DEL and RD commands to get prompted before any damage is done.

Jim

/* If you think the problem is bad now, wait until I solve it! */

by lyonjr

I know this is an old post, but I am searching for help. I tried your first example in a batch file and it works for my profile, but not others. I get "The system cannot find the path specified" errors. I am an admin on the PCs so access is not the problem. Any ideas? Thanks in advance for any help you can offer.

by tobif

You're probably on Vista.
If you take a closer look, you'll find that "Documents and settings" changed name to "users".

But, seriously, before using any such powerful toys, you should analyze it enough to understand what it does, and how. Just to be sure that this is what you need.

So, when you feel right about this, you may find that you need to run the cmd with elevated rights to do this.

by lyonjr

Thanks for your reply.

No, I am not on Vista, but XP Pro. I am running it as an Administrator and it only works for the currently logged in user. None of the other profiles are changed. I understand the commands in the batch, I just can't figure out why it only works for the currenty logged in user.

This discussion is closed to new replies.