Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookies, Temp, Recent, Delete Routine

Status
Not open for further replies.

dball63

MIS
Jan 31, 2001
308
US
think I'm at the right forum fo this type of question.
I am an admin at an attorney's office of 75 users. I have been wanting to create a batch file or script that will cleanup my users profile folders without my having to visit the PC personally.
I'd love to be able to just right a batch file that would delete
C:\DOCUMENTS AND SETTINGS\USERNAME\COOKIES\*.*
C:\DOCUMENTS AND SETTINGS\USERNAME\RECENT\*.*
C:\DOCUMENTS AND SETTINGS\USERNAME\COOKIES\*.*
C:\DOCUMENTS AND SETTINGS\USERNAME\LOCAL SETTINGS\TEMP\*.*
C:\DOCUMENTS AND SETTINGS\USERNAME\LOCAL SETTINGS\TEMPORARY INTERNET FILE\*.*
C:\WINNT\TEMP\*.*
and put it in a login script but I can't figure a way around the USERNAME profile variable so I figured scripting was probably the way to go.
Problem! I have NO experience writing script and I am not sure that I am capable of it given the right material (I've got many other things on my plate).
Can someone help me out with a sample script that may be close to what looking for?
I'm hope that for someone who does this stuff often this will seem an easy task.

David Ball CNE, MCSE
Information Systems
 
With batch file you could have a line:

del /c /q "C:\DOCUMENTS AND SETTINGS\%USERNAME%\COOKIES\*.*
del /c /q "C:\DOCUMENTS AND SETTINGS\%USERNAME%\LOCAL SETTINGS\TEMP\*.*

etc...

the %username% will be replace by the os with the current user.

Test it as you will see it doesn't delete everything. It will however get rid of most of the rubbish.

 
in vbscript - save the code below into a text file and call it cleanup.vbs

Set fso = Wscript.CreateObject("Scripting.FilesystemObject")
set wshNetwork = Wscript.CreateObject("Wscript.Network")
struser = wshNetwork.UserName
fso.DeleteFile "C:\DOCUMENTS AND SETTINGS\" & struser & "\COOKIES\*.*",Force
fso.DeleteFile "C:\DOCUMENTS AND SETTINGS\" & struser & "\RECENT\*.*", Force
fso.DeleteFile "C:\DOCUMENTS AND SETTINGS\" & struser & "\COOKIES\*.*",Force
fso.DeleteFile "C:\DOCUMENTS AND SETTINGS\" & struser & "\LOCAL SETTINGS\TEMP\*.*",Force
fso.DeleteFile "C:\DOCUMENTS AND SETTINGS\" & struser & "\LOCAL SETTINGS\TEMPORARY INTERNET FILE\*.*",Force
fso.DeleteFile "C:\WINNT\TEMP\*.*",Force
Regards
Steve Friday
 
update.
I've tried both of the above and had the best luck w/ the batch file, probably because I am more familiar with them. The VB script returned error "Line 4, somthing about permissions on the directory I think"

Anyway.....I modified it some and it seems that the batch file is working pretty well. Although it seems that after running the batch file most of the files are gone except those in Temporary Internet Files folder which are really the ones that should be cleaned! It may be that MS is doing something strange with that folder that I am not aware of?

This is what my batch looks like, thanks for your help. It appears that my variables were OK but I needed 8.3 naming.

****************************
del /F /S /Q C:\docume~1\%USERNAME%\cookies\*.*
del /F /S /Q C:\docume~1\%USERNAME%\recent\*.*
del /F /S /Q C:\docume~1\%USERNAME%\locals~1\temp\*.*
del /F /S /Q C:\docume~1\%USERNAME%\locals~1\tempor~1\*.*
del /F /S /Q C:\winnt\temp\*.*
REM del /F /S /Q C:\recycler\*.*
*********************************

David Ball CNE, MCSE
 
You don't need 8.3 names.. chuckster forgot trailing quotes on each of his lines.

sFriday pulled the "Force" keyword out of thin air (or most likely, a book). Each line should end with ",True" to force the deletion.

This will get the user profile part:
Set wshShell = CreateObject("wscript.shell")
wshShell.ExpandEnvironmentStrings("%USERPROFILE%")
 
This could be a really BAD idea, but you could create a batch file and reference it in your Autoexec.bat file that would delete all those directories and then re-create them. I don't believe there are any files in those directories that can't be re-created on the fly without user intervention or error.

So, for example, in your batch file you'd have:

deltree c:\windows\tempmkdir c:\windows\temp
If you're using NTFS you might not be able to do this. You can definitely do it in regular old DOS.

Do NTFS partitions have autoexec.bat files? Can't remember off the top of my head.

Again, this could be a dangerous thing. Test it extensively before you implement it! :)

Onwards,

Q-
 
Oops. That does not solve your 'USERNAME' problem. Sorry about the incorrect answer. :-(

Onwards,

Q-
 
I did get this to work on NTFS drives. THe batch file is caled from login script every tuesday. The file looks exactly like this and it has worked flawlessly for over 6 months now.

@echo off
echo please wait while modifications are made are made to your system...

del /F /S /Q C:\docume~1\%USERNAME%\cookies\*.*
del /F /S /Q C:\docume~1\%USERNAME%\recent\*.*
del /F /S /Q C:\docume~1\%USERNAME%\locals~1\temp\*.*
del /F /S /Q C:\docume~1\%USERNAME%\locals~1\tempor~1\*.*
del /F /S /Q %SystemRoot%\temp\*.*
REM del /F /S /Q C:\recycler\*.*
REM *******ADD THIS LINE FOR XP WORKSTATIONS*****
REM del /F /S /Q %SystemRoot%\prefetch\*.*


David Ball CNE, MCSE
 
You mean, I was right???

Or, at least, I was close???

Wow. Cool. :)

Onwards,

Q-
 
This should answer your questions on how to handle the %Profile% in a string, it will also pull the temp dir directly from the users reg-file so that you hit the correct directory regardless of where it’s at.

On Error Resume Next
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
Set objFSO = CreateObject("Scripting.FileSystemObject")
'this will resolve the %profile% to "C:\Documents and Settings\joeg"
envUserPro = wshShell.ExpandEnvironmentStrings("%USERPROFILE%")
'Clean out the temp Dir
regTemp=WshShell.RegRead("HKCU\Environment\temp")
'this will sub in the resovled profile into the string pulled form the reg.
cTempDir = replace(regTemp, "%USERPROFILE%",envUserPro,1)
objFSO.DeleteFolder cTempDir,true
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top