|
2#
楼主 |
发表于 2011-7-8 17:48:51
|
只看该作者
我自己搞定了。。
还能进一步优化一下。下面是代码。
'*********************************************
'Del_CookieCache返回一个长度为3的Dictionary
'第一个为cookie路径
'第二个为cache路经
'第三个为错误状态(用于判断是否是WIN7或XP系统)
'*********************************************
Function Del_CookieCache()
'设置Dictionary用于存储返回的三个字符串
Dim obj_Dictionary,a,b,c
Set obj_Dictionary = CreateObject ("Scripting.Dictionary")
'获取当前操作系统
Dim wmiService,wmiObjects,wmiObject
Set wmiService = GetObject("winmgmts:\\.\root\cimv2")
Set wmiObjects = wmiService.ExecQuery("SELECT * FROM Win32_OperatingSystem")
For Each wmiObject In wmiObjects
str_Systype = wmiObject.Caption
next
str_Systype = Trim(str_Systype)
' MsgBox ("操作系统类型:"&str_Systype)
'根据操作系统类型设置cookie与cache在注册表的位置
Dim str_cookiePath_forWin7,str_CachePath_forWin7
Dim str_cookiePath_forWinXP,str_CachePath_forWinXP
Dim str_CookiePath,str_CachePath
Dim objWshShell,objWshShell_P
Dim error_code
error_code = 0
Set objWshShell = CreateObject("wscript.shell")
str_cookiePath_forWin7 = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\cookies"
str_cookiePath_forWinXP = "KEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Special Paths\Cookies\Directory"
str_CachePath_forWin7 = "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\cache"
str_CachePath_forWinXP = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Paths\Directory"
Select Case str_Systype
Case "Microsoft Windows 7 专业版"
str_CookiePath = objWshShell.RegRead(str_cookiePath_forWin7)
str_CachePath = objWshShell.RegRead(str_CachePath_forWin7)
error_code = 0
Case "Microsoft Windows XP Professional"
str_CookiePath = objWshShell.RegRead(str_cookiePath_forWinXP)
str_CachePath = objWshShell.RegRead(str_CachePath_forWinXP)
error_code = 0
Case Else
str_CookiePath = ""
str_CachePath = ""
error_code = 1
End Select
obj_Dictionary.Add "0",CStr(error_code )
obj_Dictionary.Add "1",CStr(str_CookiePath)
obj_Dictionary.Add "2",CStr(str_CachePath)
Set Del_CookieCache = obj_Dictionary
' For i = 0 To 2 Step 1
' MsgBox obj_Dictionary.Item(i)
' Next
End Function
Function del_exc()
Dim objTmp_Dictionary,wsh
Dim error_code,cookie_path,cache_path
'定义要删除的cookie类型
cookie_type = "\*paipai*"
Set objTmp_Dictionary = Del_CookieCache
error_code = objTmp_Dictionary.Item("0")
cookie_path = objTmp_Dictionary.Item("1")
cache_path = objTmp_Dictionary.Item("2")
' MsgBox cookie_path
' 由于%userprofile%是环境变量,不是绝对路径
' 所以不能被filesystemobject对象识别,不能使用folderexists来判断,若必须用,则需要获取当前用户名并替换%userprofile%
' 需要改为cmd构造命令来执行,
If error_code = "1" Then
MsgBox "当前操作系统未添加"
Exit Function
ElseIf error_code = "0" Then
Set wsh = CreateObject("Wscript.shell")
wsh.Run "%comspec% /C del /F /Q "&cookie_path&"\*.*"
wsh.Run "%comspec% /C del /F /Q "&cache_path&"\*.*"
End If
End Function
Call del_exc() |
|