Your scriupt does work but not on all profiles. I created few folders and files those also did not delete. Any ways...Can you see the attached script which i use to remotely delete. if some thing like this can be added it would help. Code from Rob
' Delete_Temp_Files_Remotely
Option Explicit
Dim objShell, objNetwork, objProcess, strUserName, strHostName, strCommand, strAdminUser, strAdminPass, strComputer
Dim objWMIService, colComputer, objComputer, boolClearCache, objFSO, strTempFiles
Dim strCacheLog, objInputFile, objFile, strFilePath, objSubFolder, objCacheLog, boolFound
Const intForReading = 1
If Left(WScript.ScriptFullName, 2) <> "\\" Then
MsgBox "Please run this script from a UNC path."
WScript.Quit
End If
Set objShell = CreateObject("Wscript.Shell")
Set objProcess = objShell.Environment("Process")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strUserName = objProcess("USERNAME")
strHostName = objProcess("COMPUTERNAME")
If WScript.Arguments.Count < 1 Then
Call Normal_User_Commands
ElseIf WScript.Arguments(0) = "AsAdmin" Then
Call Admin_User_Commands
Else
MsgBox "Unknown Argument received"
End If
Sub Normal_User_Commands
' Enter your Administrative credentials here
strAdminUser = InputBox("Enter user name:", "User name", "DEVELOPMENT\Administrator")
strAdminPass = InputBox("Enter the password for " & strAdminUser & ":", "Password")
'MsgBox "Running as initiating user"
'strComputer = "."
Set objInputFile = objFSO.OpenTextFile("Computers.txt", intForReading, False)
While Not objInputFile.AtEndOfStream
'*********************** THIS MSGBOX CAN BE REMOVED FOR A LOGON SCRIPT *******************
' If this MsgBox is used, the admin commands can be run on a remote machine.
'strComputer = InputBox("Enter computer to clear Temporary Internet Files on:", "Enter Computer", "172.16.2.64")
'******************************************************************************************
strComputer = objInputFile.ReadLine
If Ping(strComputer) = False Then
'MsgBox strComputer & " did not respond to ping. Cannot continue script."
WriteToLog strComputer & " did not respond to ping. Cannot continue script."
Else
On Error Resume Next
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
If Err.Number = 0 Then
Err.Clear
On Error GoTo 0
' This command assumes that PSExec.exe (available from Microsoft) is stored on the shared folder
' below. It runs PSExec as the Admin user, on a remote machine, or the current machine if it is a
' logon script. It re-runs this file again, this time passing the "AsAdmin" argument, so the script
' knows it has been run under an Admin account, and can safely execute the Admin_User_Commands Sub.
' NOTE: If the Admin is running this script from a mapped drive, the client must have the same drive mapped,
' because of the use of WScript.ScriptFullName below. It is best to run this script from a UNC path,
' so the client machine can access the file via a UNC path and not rely on a mapped drive.
WriteToLog " *** *** Starting Script against all users on " & strComputer & ": " & Now
strCommand = "cmd /c \\hos\Ps\psexec.exe -accepteula -i -e -u " & strAdminUser & " -p " & strAdminPass & " \\" & strComputer & " WScript """ & WScript.ScriptFullName & """ AsAdmin"
objShell.Run strCommand, 1, True
' NOTE: In the above two lines, you can change the cmd /c to cmd /k and the strCommand, 0, True to strCommand, 1, True
' if you wish to see some output for debugging / testing purposes.
'MsgBox "Finished running on " & strComputer
Else
Err.Clear
On Error GoTo 0
MsgBox "Error connecting to " & strComputer
WriteToLog "Error connecting to " & strComputer
End If
End If
Wend
End Sub
Sub Admin_User_Commands
' Now the script has detected that "AsAdmin" was passed to it, and will run these commands.
' Now running as Administrator on the target macchine
' MsgBox "Running as Admin"
For Each objSubFolder In objFSO.GetFolder(objShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%") & "\Documents and Settings\").SubFolders
boolFound = False
strTempFiles = objSubFolder.Path & "\Local Settings\Temporary Internet Files"
If objFSO.FolderExists(strTempFiles) = False Then
'MsgBox "Could not find " & strTempFiles
WriteToLog "Could not find " & strTempFiles
'WScript.Quit
Else
boolFound = True
End If
If boolFound = True Then DeleteFilesAtPath strTempFiles
Next
For Each objSubFolder In objFSO.GetFolder(objShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%") & "\Documents and Settings\").SubFolders
boolFound = False
strTempFiles = objSubFolder.Path & "\Local Settings\Temp"
If objFSO.FolderExists(strTempFiles) = False Then
'MsgBox "Could not find " & strTempFiles
WriteToLog "Could not find " & strTempFiles
'WScript.Quit
Else
boolFound = True
End If
If boolFound = True Then DeleteFilesAtPath strTempFiles
Next
boolFound = False
strTempFiles = objShell.ExpandEnvironmentStrings("%WINDIR%") & "\Temp"
If objFSO.FolderExists(strTempFiles) = False Then
'MsgBox "Could not find " & strTempFiles
WriteToLog "Could not find " & strTempFiles
'WScript.Quit
Else
boolFound = True
End If
If boolFound = True Then DeleteFilesAtPath strTempFiles
End Sub
'======== END OF CLEAR TEMPORARY INTERNET FILES CACHE BLOCK ===========
Sub DeleteFilesAtPath(strThePath)
strTempFiles = objFSO.GetFolder(strThePath).ShortPath
'======== METHOD 1 ===================
strCacheLog = "Cache Files Cleared on " & objShell.ExpandEnvironmentStrings("%COMPUTERNAME%") & ": " & Now & VbCrLf & "========================================"
For Each objFile In objFSO.GetFolder(strTempFiles).Files
strFilePath = objFile.Path
On Error Resume Next
objFSO.DeleteFile strFilePath, True
If Err.Number = 0 Then
strCacheLog = strCacheLog & VbCrLf & "SUCCESS: " & strFilePath
Else
Err.Clear
strCacheLog = strCacheLog & VbCrLf & "FAILURE: " & strFilePath
End If
On Error GoTo 0
Next
For Each objSubFolder In objFSO.GetFolder(strTempFiles).SubFolders
Call RecurseSubFolders(objSubFolder)
Next
WriteToLog strCacheLog
'======== METHOD 2 ==================
On Error Resume Next
objFSO.DeleteFile(strTempFiles & "\*.*")
Err.Clear
On Error GoTo 0
WriteToLog "Files deleted from " & strTempFiles
RemoveEmptyFolders strTempFiles
End Sub
Sub RemoveEmptyFolders(strFolder)
strCommand = "cmd /c dir " & strFolder & " /ad/b/s | sort /r > C:\EMPTYFOLDERS.TXT"
objShell.Run strCommand, 0, True
strCommand = "cmd /c for /f ""tokens=*"" %i in (C:\EMPTYFOLDERS.TXT) do rd /q %i"
objShell.Run strCommand, 0, True
objFSO.DeleteFile "C:\EMPTYFOLDERS.TXT", True
WriteToLog "Empty folders removed from from " & strFolder
End Sub
Sub RecurseSubFolders(objFolder)
For Each objFile In objFolder.Files
On Error Resume Next
strFilePath = objFile.Path
objFSO.DeleteFile strFilePath, True
If Err.Number = 0 Then
strCacheLog = strCacheLog & VbCrLf & "SUCCESS: " & strFilePath
Else
Err.Clear
strCacheLog = strCacheLog & VbCrLf & "FAILURE: " & strFilePath
End If
On Error GoTo 0
Next
For Each objSubFolder In objFolder.SubFolders
Call RecurseSubFolders(objSubFolder)
Next
End Sub
'=======================
Function Ping(strComputer)
Dim objShell, boolCode
Set objShell = CreateObject("WScript.Shell")
boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
If boolCode = 0 Then
Ping = True
Else
Ping = False
End If
End Function
Sub WriteToLog(strText)
Set objCacheLog = objFSO.OpenTextFile(Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "ClearCacheLog.txt", 8, True)
objCacheLog.Write VbCrLf & VbCrLf & strText
objCacheLog.Close
Set objCacheLog = Nothing
End Sub
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202:





by: sedgwickPosted on 2009-11-04 at 05:03:41ID: 25738835
bsharath: why did u close the thread if it wasn't working for you?
anyway, when u run the script from the console, u should see the output for almost every line.
when u say it doesn't clear all temp folders, try to delete them yourself and see if u get popup saying Destination Folder Access Denied - You need permission bla bla, like the attached image.
if u manage to delete them manually something is wrong with the script.
File delete access denied popup