0

I am trying to write the script to clear the cache on IE9 Windows7 (64 Bit). So far I have written below code. This code works fine on IE8 and Windows XP, but when I am trying to run same code on WIndows7 (IE9) it gives error by saying "Permission denied Line (39): "fso.DeleteFile (strWinFolder & "\Temp*."), True : fso.DeleteFolder (strWinFolder & "\Temp*."), True". "

Please check my script and correct me where I am doing wrong. Pardon me if I am wrong some where.

Dim methodName, fso, WshNetwork, WshShell, strVer, OSver, strWinFolder, strTempFolder, GetOS, strProfile, WindowsFolder, TemporaryFolder, NewFolder

Set fso = CreateObject("Scripting.FileSystemObject") : Set WshNetwork = CreateObject("Wscript.Network") 
set WshShell = createobject("wscript.shell") : set strVer = WshShell.exec("cmd /c ver") 
OSver = strVer.stdout.readall 

If InStr(OSver, "XP") Then GetOS = "WXP" : If InStr(OSver, "2000") Then GetOS = "W2K"
If InStr(OSver, "NT") Then GetOS = "NT4" : If InStr(OSver, "98") Then GetOS = "W98" 
If InStr(OSver, "Millennium") Then GetOS = "W98"

strWinFolder =  fso.GetSpecialFolder(WindowsFolder)
'strTempFolder =  fso.GetSpecialFolder(TemporaryFolder)

If GetOS = "WXP" OR GetOS = "W2K" Then
    Flag1 = True
    strProfile = "c:\Documents and Settings\"
Else
    Flag1 = False
End If

If GetOS = "NT4" Then
    Flag2 = True
    strProfile = "c:\winnt\profiles\"
Else
    Flag2 = False
End If

If Flag1 = False and Flag2 = False Then
    GetOS = "W7"
    Flag3 = True
    strProfile = "C:\Users\"
Else
    Flag3 = False
End If

'Delete the Temp files in the C:\Users folder. 
    If fso.FolderExists(strWinFolder & "\Temp\") Then 
        fso.DeleteFile (strWinFolder & "\Temp\*.*"), True : fso.DeleteFolder (strWinFolder & "\Temp\*.*"), True 
    End If 
    If  Not fso.FolderExists(strWinFolder & "\Temp\") Then NewFolder = fso.CreateFolder (strWinFolder & "\Temp\") End If

If Flag1 = True And Flag2 = True Then   
'Delete the recently viewed document links in the C:\Documents and Settings\"USERNAME"\Recent folder. 
    If fso.FolderExists(strProfile & WshNetwork.username & "\Recent\") Then fso.DeleteFile  (strProfile & WshNetwork.username & "\Recent\*.*"), True End If 
'Delete the Temp files in the C:\Documents and Settings\"USERNAME"\Local Settings\Temp folder. 
    If fso.FolderExists(strProfile & WshNetwork.username & "\Local Settings\Temp\") Then 
        'fso.DeleteFile (strProfile & WshNetwork.username & "\Local Settings\Temp\*.*"), True 
        'fso.DeleteFolder (strProfile & WshNetwork.username & "\Local Settings\Temp\*.*"), True 
    End If 

'Delete the Temporary Internet files and folders in the C:\Documents and Settings\"USERNAME"\Local Settings\Temporary Internet Files folder. 
    'wshShell.run "cmd /c del " & strprofile & WshNetwork.Username & "\Tempor~1\*.* /q", 1, True 
    'fso.DeleteFile (strProfile & WshNetwork.username & "\Tempor~1\*.*"), True 
    If fso.FolderExists(strProfile & WshNetwork.username & "\Local Settings\Temporary Internet Files\") Then 
        fso.DeleteFile (strProfile & WshNetwork.username & "\Local Settings\Temporary Internet Files\*.*"), True 
        'fso.DeleteFile (strProfile & WshNetwork.username & "\Local Settings\Temporary Internet Files\Content.IE5\*.*"), True 
    End If 
End If

If Flag3 = True Then
'Delete the Recent files on WIndows7    C:\Users\AA24800\AppData\Roaming\Microsoft\Windows\Recent
    If fso.FolderExists(strProfile & WshNetwork.username & "\AppData\Roaming\Microsoft\Windows\Recent") Then
        fso.DeleteFile (strProfile & WshNetwork.username & "\AppData\Roaming\Microsoft\Windows\Recent\*.*"), True 
    End If

'Delete Temporary Internet Files on WIndows7
    If fso.FolderExists(strProfile & WshNetwork.username & "\AppData\Local\Microsoft\Windows\Temporary Internet Files") Then
        fso.DeleteFile (strProfile & WshNetwork.username & "\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*"), True
    End If
End If
set fso = Nothing : set wshshell = Nothing : set WshNetwork = Nothing : set NewFolder = Nothing 
4

1 回答 1

2
' This script clears the cache of Internet Explorer
' Tested  on windows 7 workstation (IE9)

on error resume next
Dim objShell
Set objShell = CreateObject("WScript.Shell")
objShell.Run ("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2")
objShell.Run ("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255") ' ALl
objShell.Run ("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1") 'History
objShell.Run ("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2") ' Cookies
objShell.Run ("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8") ' Temp Internet Files
objShell.Run ("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16") ' Form Data
objShell.Run ("RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32") ' Passwords
'objShell.Run ("rundll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351")' All
Wscript.Quit

If err.number <> 0 Then
    WScript.Echo ("Script Check Failed") 
    Wscript.Quit (1001)
Else
    WScript.Echo ("Successfully Passed")
    WScript.Quit(0) 
End If
于 2015-05-29T20:22:58.710 回答