Search code examples
vbscriptinternet-explorer-11winhttpwinhttprequestie11-developer-tools

ClearMyTracksByProcess Without Dialog | WinHttp.WinHttpRequest.5.1 | MSXML2.XMLHTTP


I have a VBS that runs CreateObject("MSXML2.XMLHTTP").Open "GET" however, I need to delete the IE11 cache before it runs because the get keeps pulling a cached version of the website that wont expire for 1 minute after the inital get. If I use RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8 a dialog is shown that is distracting and takes focus.

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

Does not change the file cache, still expires one minute after initial pull.

+++++++++++++++++++++++++++++++++++++++

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 returns nothing

++++++++++++++++++++++++++++++++++++++

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

Both still randomly show a popup dialog.


Solution

  • 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.