WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WinInet
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Require Certificate for HTTPS Downloads


Question:

I am using Winbatch to automate file downloads from https websites. The program works great until a site is reached requiring a certificate.

Manually through IE6 the process works, (only one certificate is installed and I have the trusted root certificate for the company installed). The website is also configured as a trusted site.

I have tried using the various options under the iHttpInit with respect to certificates to no avail. I still receive the WinInet 12044 error.

Example code:

tophandle=iBegin(0,"","")
connecthandle=iHostConnect(tophandle,sHost,@HTTPS,sUser,sPass)
datahandle=iHttpInit(connecthandle,"GET",URL,"",0) 
Any thoughts as to how I can assign an existing certificate to be used with the Winbatch?

In short, it appears winbatch will work when an HTTPS does not require a certificate (ie. automating the process) but when it does require the certificate the 12044 WinInet error comes up.

Answer:

Here is some OLE code that allows you to specify a certificate.
;   I was able to download pages from the winbatch site using winbatch and HTTP via OLE...

;   HTTPS looks about the same and you can set the Client Cert in it...

;Example Code
;
;The following example shows how to select a client certificate to send with a request. 
;A certificate with the subject "My Middle-Tier Certificate" is chosen from the "Personal" 
;certificate store in the registry under 
;
;HKEY_LOCAL_MACHINE

;  is your certificate in the same place in the registry as below ??? ...

WinHttpReq = objectopen("WinHttp.WinHttpRequest.5")
WinHttpReq.SetCredentials("user", "password", "")
WinHttpReq.Open("GET", "https://www.fabrikam.com/", @false)
WinHttpReq.SetClientCertificate("LOCAL_MACHINE\Personal\My Middle-Tier Certificate") ;<---
WinHttpReq.Send()

message("Debug", WinHttpReq.ResponseText)

oh = fileopen("C:\Test\winbatch.html", "write")
filewrite(oh, WinHttpReq.ResponseText)
fileclose(oh)

message("Debug", "All Done")

exit

; actual VB Code...

;Dim HttpReq As Object
;
;    ' Instantiate the WinHTTPRequest ActiveX Object.
;    Set HttpReq = New WinHttpRequest
;    
;    ' Open an HTTP connection.
;    HttpReq.Open "GET", "https://www.fabrikam.com/", False
;    
;    'Select a client certificate.
;    HttpReq.SetClientCertificate "LOCAL_MACHINE\Personal\My Middle-Tier Certificate"
;
;    ' Send the HTTP Request.
;    HttpReq.Send
Note: There has been some work being done in this area of the WinInet Extender. Hopefully in the next release of the extender we will offer a function which will allow you to prompt the user for a certificate.

Note: Starting in version 25070 - Added new function iErrorDialog(handle, error) Displays a dialog box for the error that is passed to InternetErrorDlg, if an appropriate dialog box exists. In the case of ERROR_INTERNET_CLIENT_AUTH_CERT_NEEDED error it will prompt the user to choose a certificate.

For More information about this issue read: http://support.microsoft.com/default.aspx?scid=kb%3ben-us%3b224282


Article ID:   W15875
File Created: 2017:07:28:12:58:48
Last Updated: 2004:03:30:14:41:19