vbscript - 没有对话框的 ClearMyTracksByProcess | WinHttp.WinHttpRequest.5.1 | MSXML2.XMLHTTP
问题描述
我有一个运行的 VBS,CreateObject("MSXML2.XMLHTTP").Open "GET"
但是,我需要在它运行之前删除 IE11 缓存,因为 get 会不断提取网站的缓存版本,该版本在初始 get 后 1 分钟内不会过期。如果我使用RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8
一个对话框,则会显示分散注意力并集中注意力。
myURL = "https://localhost/"
Set ohtmlFile = CreateObject("htmlfile")
Set oXMLHttp = CreateObject("MSXML2.XMLHTTP")
oXMLHttp.Open "GET", myURL , False
oXMLHttp.setRequestHeader "Cache-Control", "no-cache"
oXMLHttp.send
If oXMLHttp.Status = 200 Then
ohtmlFile.Write oXMLHttp.responseText
ohtmlFile.Close
不更改文件缓存,在初始拉取后一分钟仍然过期。
+++++++++++++++++++++++++++++++++++++++++++
myURL = "https://localhost/"
Set ohtmlFile = CreateObject("htmlfile")
Set oXMLHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
oXMLHttp.Open "GET", myURL , False
oXMLHttp.setRequestHeader "Cache-Control", "no-cache"
oXMLHttp.send
If oXMLHttp.Status = 200 Then
ohtmlFile.Write oXMLHttp.responseText
ohtmlFile.Close
oXMLHttp.responseText 不返回任何内容
++++++++++++++++++++++++++++++++++++++++++
CreateObject("WScript.Shell").Run "scripts\exe\PsExec64.exe -accepteula -nobanner -realtime -d RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8", 0, True
CreateObject("WScript.Shell").Run "scripts\exe\PsExec64.exe -accepteula -nobanner -realtime -d RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 264", 0, True
两者仍然随机显示一个弹出对话框。
解决方案
To avoid getting a cached response, you can use ServerXmlHttpRequest
object instead and set the Cache-Control
header:
Set oXMLHttp = CreateObject("Msxml2.ServerXMLHTTP")
With oXMLHttp
.open "GET", myURL, False
.setRequestHeader "Cache-Control", "max-age=0"
.send
End With
It should also work with the WinHTTPRequest
object:
Set oXMLHttp = CreateObject("WinHttp.WinHttpRequest.5.1")
In my experience, with WinHttpRequest, you don't even need to set the Cache-Control
header so you might be all set just by changing MSXML2.XMLHTTP
to WinHttp.WinHttpRequest.5.1
in your code. Can't hurt to add the header though.
This should solve the initial problem you are having of pulling a cached version.
推荐阅读
- amazon-web-services - AWS Loadbalancer 在发送完整的 http 响应之前终止 http 调用
- google-cloud-platform - 为什么 GCE 负载均衡器通过域名和 IP 地址表现不同?
- python - 在 Python 中遍历字典
- github-actions - 在 Github Actions 中的所有作业之后,我如何创建作业以运行
- javascript - 将 Django REST 框架数据转换为 javascript 数组时缺少值
- java - 自定义异常类的修饰符(java)
- php - 使用 PHP 和 HTML 为表中的每一行创建复选框。我如何在 PHP 部分调用它们?
- python - 尝试使用 pip 安装不和谐模块时出错
- xamarin.android - Xamarin.Android 运行方法/任务,即使我的应用程序已关闭
- c - 如何在 C 中使用 fscanf() 区分文件结尾和错误?