我正在尝试编写脚本以清除IE9 Windows7(64位)上的缓存。 到目前为止我已经写了下面的代码。 这段代码在IE8和Windows XP上运行正常,但是当我试图在WIndows7(IE9)上运行相同的代码时,它会说“权限被拒绝” 第(39)行:“fso.DeleteFile(strWinFolder&”\ Temp *。“),True:fso.DeleteFolder(strWinFolder&”\ Temp *。“),True”。 “
请检查我的脚本,并纠正我在哪里做错了。 如果我错了,请原谅我。
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
答案 0 :(得分: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