Script to delete temp files on xp machines

I'm trying to write a vbs or wsh script to delete temp files and temp internet files on xp machines.  Deleting these files and folders isnt a problem, but how do I get down to the c:\documents and settings\username\local settings\temp folder to delete these files.  
oregonmutualAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

aelatikCommented:
You can get the desktop and from there you can change desktop to "local settings/temp".

Set WshShell = Wscript.CreateObject("WScript.Shell")
Wscript.Echo Replace(WshShell.SpecialFolders("Desktop"), "Desktop", "local settings\temp")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ToolManCommented:
Hi there,

about your Q:
i myself use the following to cleanup tempfiles -->

REM ---------BOF-----------
@echo off
echo Cleaning up tmp files..........
md c:\robocopy
robocopy c:\robocopy "c:\Temp" /mir /r:1 /w:1
robocopy c:\robocopy "%userprofile%\Local Settings\Temp" /mir /r:1 /w:1
robocopy c:\robocopy "%temp%" /mir /r:1 /w:1
robocopy c:\robocopy "%tmp%" /mir /r:1 /w:1

robocopy c:\robocopy "%userprofile%\Local Settings\Temporary Internet Files" /mir /r:1 /w:1
robocopy c:\robocopy "%userprofile%\Local Settings\History" /mir /r:1 /w:1
robocopy c:\robocopy "%userprofile%\Application Data\Microsoft\Office\Recent" /mir /r:1 /w:1
robocopy c:\robocopy "%userprofile%\recent" /mir /r:1 /w:1
robocopy c:\robocopy "%userprofile%\Cookies" /mir /r:1 /w:1
robocopy c:\robocopy "%userprofile%\NetHood" /mir /r:1 /w:1
robocopy c:\robocopy %SystemRoot%\Temp  /mir /r:1 /w:1
robocopy c:\robocopy %SystemRoot%\Minidump  /mir /r:1 /w:1
robocopy c:\robocopy "%ALLUSERSPROFILE%\Documents\DrWatson"  /mir /r:1 /w:1
robocopy c:\robocopy "%userprofile%\Local Settings\Application Data\Microsoft\Terminal Server Client\Cache"  /mir /r:1 /w:1
rd c:\robocopy
REM ---------EOF-----------

ti's a DOS batchfiles and works great for me, however it does use the ROBOCOPY.EXE copy resoursekit utility to remove the files.

hope it helps
Regards
0
ronnacCommented:
Here is a vbs script that I have successfully used for a couple of years on XP desktops. It will ask you for the name of the remote PC and display the deletion progress in an IE window. It goes through all windows profiles on that remote PC.

'---------BOF-----------
strComputer = Inputbox ("PC, on which you want to delete temp files:")

If strComputer = "" Then
      Wscript.Quit
End IF

Set Locator = CreateObject("WbemScripting.SwbemLocator")
Set Service = Locator.ConnectServer(strComputer, "root/cimv2")
Set Security = Service.Security_
Security.ImpersonationLevel = 3



'open message screen
'*******************

Set objExplorer = WScript.CreateObject ("InternetExplorer.Application")
objExplorer.Navigate "about:blank"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 800
objExplorer.Height = 300
objExplorer.Left = 0
objExplorer.Top = 0
objExplorer.Visible = 1
objExplorer.Document.Write ("<head><title>" & strComputer & " Temp Files</title></head>")
objExplorer.Document.Write ("Deleting temp files and folders on " & strComputer & "<br>")


'Looping users folders
'*********************

objExplorer.Document.Write ("Deleting Temp folders<br>")

Set filesys = CreateObject("Scripting.FileSystemObject")

Set folder = filesys.GetFolder("\\" & strComputer & "\c$\documents and settings")  
Set folcoll = folder.SubFolders  
For Each subfol in folcoll
      TempFolder = subfol & "\Local Settings\Temp"
      exec_wait("cmd /c rmdir /s /q """ & TempFolder & """")
      exec_wait("cmd /c mkdir """ & TempFolder & """")
      objExplorer.Document.Write ("Deleting " & TempFolder & "<br>")
      TempFolder = subfol & "\Local Settings\Temporary Internet Files"
      objExplorer.Document.Write ("Deleting " & TempFolder & "<br>")
      exec_wait("cmd /c rmdir /s /q """ & TempFolder & """")
      exec_wait("cmd /c mkdir """ & TempFolder & """")
Next



'executing other deletions
'*************************

TempFolder = "\\" & strComputer & "\c$\WINDOWS\TEMP"
objExplorer.Document.Write ("Deleting " & TempFolder & "<br>")
exec_wait("cmd /c rmdir /s /q """ & TempFolder & """")

'recreate c:\windows\temp if necessary
If NOT filesys.FolderExists(TempFolder) Then
      filesys.CreateFolder TempFolder
End IF

If filesys.FolderExists(TempFolder) Then
      TempFolder = "\\" & strComputer & "\c$\WINDOWS\SoftwareDistribution\download"
      If filesys.FolderExists(TempFolder) Then
            objExplorer.Document.Write ("Deleting " & TempFolder & "<br>")
            exec_wait("cmd /c rmdir /s /q """ & TempFolder & """")
      End IF
End IF


objExplorer.Document.Write ("Deleting remaining *.tmp files<br>")

exec_wait("cmd /c c: && cd .. && cd .. && cd .. && del *.tmp *.~* ~*.* *.??~ *.--- *._mp *~tmp.* *.??$ /s /q")

objExplorer.Document.Write ("Done.<br>")
objExplorer.Document.title = "DONE: "& strComputer & " Temp Files."

'FUNCTIONS
'*********


'remotely execute and wait
'-------------------------

Function exec_wait(App)

      Set Proc = Service.Get("Win32_Process")

      errReturn = Proc.Create(App, Null, Null, intProcessID)

      ' errReturn will not give any install status, it only indicates
      ' if the app was successfully launched or not
      If errReturn = 0 Then
        ' wait for the process to finish
        On Error Resume Next
        Do
           WScript.Sleep 1000
           Set objMyProcess = Service.Get("Win32_Process='" & intProcessID & "'")
           If Err.Number <> 0 Then
           ' Process has finished or terminated
              bolDone = True
           Else
              bolDone = False
           End If
        Loop Until bolDone
        On Error Goto 0
      End If

End Function


'Get RegKey Function
Function GetRegKeyStrValue (sComputer, hTree, sKey, sString, sValue)
      Dim oRegistry
      Dim lResult

      Set oRegistry      = GetObject("winmgmts:{impersonationLevel=impersonate}//" & sComputer & "/root/default:StdRegProv")
      lResult = oRegistry.GetStringValue(hTree,   sKey,  sString ,sValue)
      If (lResult = 0) And (Err.Number = 0) Then
         GetRegKeyStrValue = sValue
      Else
         GetRegKeyStrValue = "Failed"
      End If
      Set oRegistry = Nothing
End Function

'---------EOF-----------

********************************************************************

NOTE!!!!!!!!!!!! Do not use this script on any xp or Server machine or you will destroy it - I only post here as i learnt the hard way on numerous machines and do not want anyone else to suffer what i have just finished dealing with

Jay_Jay70
EE Zone Advisor

*******************************************************************
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.