1

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.

  • Did you try to set request like this? .setRequestHeader "cache-control", "no-cache" If not, you can have a test on your side to check whether it helps to solve the issue or not. – Deepak-MSFT Oct 07 '19 at 07:01
  • I gave it a shot, same results, expiration is still set at one minute from initial pull. –  Oct 07 '19 at 11:33
  • 1
    Is it possible for you to provide a sample of the web page with which we can test this code to check for the issue? because we are not able to produce the issue with only above code. It can help to narrow down the issue. – Deepak-MSFT Oct 08 '19 at 03:05

1 Answers1

0

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.

Étienne Laneville
  • 4,697
  • 5
  • 13
  • 29
  • When I apply `Msxml2.ServerXMLHTTP` or `WinHttp.WinHttpRequest.5.1` I do not receive any data back from the open. Also, when I use `oXMLHttp.setRequestHeader "Cache-Control", "max-age=0"` the cache expiration is still saved as one minute after the initial request. –  Oct 07 '19 at 02:18
  • You will get data back on the `.send` call. Usually you want to provide a request string but that's not shown in your question. You can use `.responseText` to get the response from the server. As far as the `"Cache-Control", "max-age=0"` header is concerned, from what I have read, it is not acknowledged if you use `MSXML2.XMLHTTP`. My advice is to use `WinHttp.WinHttpRequest.5.1` which doesn't need any header. Please edit your question to show what you have tried so far. You should be able to get a non-cached response without getting into this much trouble. – Étienne Laneville Oct 07 '19 at 02:58
  • Question updated. The block surrounded by ++++++ does not return any responseText –  Oct 07 '19 at 11:31
  • I tested the code and it works, I suspect perhaps `myURL` is not returning anything. Try setting `myURL = "https://postman-echo.com/get?foo1=bar1&foo2=bar2"` just to eliminate your URL. – Étienne Laneville Oct 07 '19 at 18:00
  • 1
    Looks like its a cookie issue...... When I run the postman url it works, when I run my url (which uses a login cookie) im redirected to the login page. Does WinHttp.WinHttpRequest.5.1 not work with stored cookies? –  Oct 08 '19 at 03:20
  • Think I found it `setResponseHeader("Set-Cookie")` –  Oct 08 '19 at 03:25
  • So, I'm guessing since the cookie is set in IE 11 I cant use it to log into the session that's being created with WinHttp.WinHttpRequest.5.1 ? –  Oct 08 '19 at 03:34
  • You're working with a Request, not a Response. I think what you found is for the Server to send Cookies to your web browser. If you need credentials for your API, you can set Request headers for those, you need to check what the API is expecting. Please add information about your API to your question or perhaps post a new question. I think the matter of getting cached data is resolved. – Étienne Laneville Oct 08 '19 at 03:34
  • Glad I could help. I think passing credentials should be easy to figure out, there are a lot of examples available. Keep in mind that your HTTP Request object is independent of your IE settings. Good luck and come back to Stack Overflow for your programming questions! – Étienne Laneville Oct 08 '19 at 03:40
  • 1
    @ÉtienneLaneville There is someone that always wants to downvote any answer in vbscript section even that this later can be accepeted like your case and i know him i will upvote you +1 – Hackoo Oct 08 '19 at 23:42
  • @Hackoo thanks!! Been wondering about those downvotes! I appreciate you noticing all of that and helping out people getting downvoted. – Étienne Laneville Oct 09 '19 at 00:04