Vbscript to download a file (bypassing invalid certificate errors)

dim xHttp: Set xHttp = createobject("microsoft.xmlhttp")
dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", "https://www.website.com/apps/CertMgr.Exe", False
xHttp.Send

with bStrm
    .type = 1 '//binary
    .open
    .write xHttp.responseBody
    .savetofile "c:\CertMgr.Exe", 2 '//overwrite
end with

Using the code above, I'm trying to download a file from a secure site to automatically install a security certificate, it works fine with an http site, but I need to bypass security errors. Any ideas?

+3
source share
1 answer

You need to switch from MSXML2.XMLHTTP to MSXML2.ServerXMLHTTP and use setOption with the value SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS . Just put the call between Open and Send. Here your example is updated with new code.

const SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS = 13056
dim xHttp: Set xHttp = createobject("MSXML2.ServerXMLHTTP")
dim bStrm: Set bStrm = createobject("Adodb.Stream")
xHttp.Open "GET", "https://www.website.com/apps/CertMgr.Exe", False
xHttp.setOption 2, SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS
xHttp.Send

with bStrm
    .type = 1 '//binary
    .open
    .write xHttp.responseBody
    .savetofile "c:\CertMgr.Exe", 2 '//overwrite
end with
+4
source

Source: https://habr.com/ru/post/1794245/


All Articles