首页 > 解决方案 > 没有对话框的 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

两者仍然随机显示一个弹出对话框。

标签: vbscriptinternet-explorer-11winhttpwinhttprequestie11-developer-tools

解决方案


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.


推荐阅读