Copy this code into a notepad and save it as .vbs file. It can be configured in scheduler so that it can be run on a regular basis and clear your system temp files or you can double click on the file on the need basis and it do the job.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set WShell = CreateObject("WScript.Shell")
sHost = WShell.ExpandEnvironmentStrings( "%USERNAME%" )
Set WShell = Nothing
Set oFSO = CreateObject("Scripting.FileSystemObject")
sTempPath = "C:\Users\"&sHost&"\AppData\Local\Temp"
Set oFolder = oFSO.getfolder(sTempPath)
Set oSubFoldersObj = oFolder.SubFolders
Set oFilesObj = oFolder.Files
For each oFile in oFilesObj
On Error Resume Next
oFile.Delete
On Error Goto 0
Next
For each oSubFol in oSubFoldersObj
On Error Resume Next
oSubFol.Delete
On Error Goto 0
Next
set oFolder = Nothing
Set oSubFoldersObj = Nothing
Set oFilesObj = Nothing`
Set oFSO = Nothing
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Set WShell = CreateObject("WScript.Shell")
sHost = WShell.ExpandEnvironmentStrings( "%USERNAME%" )
Set WShell = Nothing
Set oFSO = CreateObject("Scripting.FileSystemObject")
sTempPath = "C:\Users\"&sHost&"\AppData\Local\Temp"
Set oFolder = oFSO.getfolder(sTempPath)
Set oSubFoldersObj = oFolder.SubFolders
Set oFilesObj = oFolder.Files
For each oFile in oFilesObj
On Error Resume Next
oFile.Delete
On Error Goto 0
Next
For each oSubFol in oSubFoldersObj
On Error Resume Next
oSubFol.Delete
On Error Goto 0
Next
set oFolder = Nothing
Set oSubFoldersObj = Nothing
Set oFilesObj = Nothing`
Set oFSO = Nothing
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
No comments:
Post a Comment