2011-02-23 29 views
3
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 

使用我試圖從一個安全的網站下載文件自動安裝安全證書上面的代碼,它工作正常,從HTTP網站,但我需要繞過安全錯誤。有任何想法嗎?VBScript來下載文件(繞過無效證書錯誤)

回答

4

您需要從MSXML2.XMLHTTP切換到MSXML2.ServerXMLHTTP,並使用值爲SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORSsetOption方法。只需在打開和發送之間進行呼叫。以下是使用新代碼更新的示例。

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 
+0

不工作:'download.vbs(2,12)的Microsoft VBScript運行時錯誤:ActiveX組件不能創建對象:microsoft.serverxmlhttp'' – Anthon 2015-05-12 12:33:22

+0

很抱歉的錯字。它應該是「MSXML2.ServerXMLHTTP」 – jveazey 2015-05-28 19:26:40