-
Jan 12th, 2018, 10:12 AM
#1
[RESOLVED] cDownload on Vista (vbRichClient5)
Hello,
I want to download a file (History.txt) from my github and process it to let the user know if an update is available.
I use this code (taken form some Olaf's example):
Code:
Dim Downloads As cDownloads, D As cDownload
URL = "https://miorsoft.github.io/Site/PhotoModularFX/History.txt"
Set Downloads = New_c.Downloads
Set D = Downloads.Download(URL)
D.WaitForCompletion 5 '3 '<- 3 seconds timeout, until we cancel the http-Request
If D.DownloadCompleted And D.GetContentLen > 0 Then
'If MainFSO.FolderExists(APP.Path & "\Update") = False Then
'MainFSO.CreateDirectory (APP.Path & "\Update")
'End If
If MainFSO.FileExists(APP.Path & "\Update") Then MainFSO.DeleteFile APP.Path & "\Update"
D.SaveContentBytesToFile APP.Path & "\Update"
F = MainFSO.ReadTextContent(APP.Path & "\Update")
...
'ELABORATE "F" and let user kbow about updates
...
Else
MsgBox "TimeOut " & D.DownloadErrorStatusString
End If
In Windows7(32) it works,
but in WindowsVista(32) it do Not work
D.DownloadErrorStatusString is "Resource Not Found"
"WaitForCompletion" seems to be skipped. Since in IDE it's executed instantly.
Maybe it's not about Windows Operative System, but about the type of Internet connection .... I do not know.
-
Jan 12th, 2018, 12:38 PM
#2
Re: cDownload on Vista (vbRichClient5)
There is an issue with modern SSL-certificates, which can cause problems on older machines
(running XP or Vista) because they don't have the matching Crypto-extensions (which Systems > Vista usually have).
Normally (on XP but also on Vista) there were System-Updates (as e.g. latest IE8 for XP or IE9 for Vista, but also Crypto-related ones),
which install newer Crypto-libs on the OS.
E.g. on an XP-VM which I tried to keep up-to-date (until support ran out), I don't get your Error.
(don't have a VISTA-VM here to check).
But on a quite old (non-updated) XP-VM which did not have IE8 installed - and no patches applied, I was able to reproduce the problem...
And even when trying to hand over an URL which does not specify the secure protocol, but only "http://" instead,
it will often not help, because many sites enforce (over a redirect-response) to reload with https instead.
Here is the (slightly changed) code, which I've ran on that failing XP-machine (using cDownloads WithEvents, to get some more info):
Code:
Option Explicit
Private WithEvents Downloads As cDownloads
Private Sub Downloads_DownloadProgress(DownloadObj As vbRichClient5.cDownload, ByVal Percent As Single, ByVal StatusCode As Long, StatusDescription As String, StatusValue As String)
Debug.Print StatusCode, StatusDescription, StatusValue
End Sub
Private Sub Form_Load()
Set Downloads = New_c.Downloads
MsgBox DownloadHistory
End Sub
Private Function DownloadHistory() As String
Const URL = "http://miorsoft.github.io/Site/PhotoModularFX/History.txt"
Dim D As cDownload
Set D = Downloads.Download(URL)
If Not D.WaitForCompletion(5) Then ' timeout-seconds, until we cancel the http-Request
DownloadHistory = "TimeOut: " & D.DownloadErrorStatusString
Exit Function
End If
If D.DownloadErrorStatus = 0 And D.GetContentLen > 0 Then
DownloadHistory = StrConv(D.GetContentData, vbUnicode)
Else
DownloadHistory = "Error: " & D.DownloadErrorStatusString
End If
End Function
Running the above on the failing XP-machine in question did print out:
Code:
1 Finding resource miorsoft.github.io
2 Connecting 151.101.113.147
11 Sending request
3 Redirecting https://miorsoft.github.io/Site/PhotoModularFX/History.txt
2 Connecting 151.101.113.147
2 Connecting 151.101.113.147
What you could try on your VISTA-machine is either:
- to update to a recent IE (not sure, whether there is somehing higher avail. for Vista than IE9) and to get "as many Updates as are still available"
- or to use the WInHttp-5.1 Object with the SSL-Error-Ignore Option (see Code below)
Code:
Private Function DownloadHistory2() As String
Const URL = "https://miorsoft.github.io/Site/PhotoModularFX/History.txt"
Dim http As New WinHttp.WinHttpRequest
http.Open "GET", URL, True
http.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All
http.Option(WinHttpRequestOption_SecureProtocols) = &HA8
http.Send
If Not http.WaitForResponse(5) Then ' timeout-seconds, until we cancel the http-Request
DownloadHistory2 = "TimeOut: " & http.StatusText
Exit Function
End If
If http.Status = 200 Then
DownloadHistory2 = StrConv(http.ResponseBody, vbUnicode)
Else
DownloadHistory2 = "Error: " & http.StatusText
End If
End Function
The MS-WinHttp-Object is the better choice for your case anyways, because it "guarantees no re-usage of cached responses".
(it is always trying to do a real server-roundtrip, retrieving fresh content - which I assume is, what you want).
The RC5-cDownload-Object is using the Systems URL-Cache - and should only be used for Downloads of relative static content (as e.g. Image-Resources or something).
HTH
Olaf
-
Jan 12th, 2018, 12:43 PM
#3
Re: cDownload on Vista (vbRichClient5)
trying to redo my XP VM, and slipstream all the latest available updates (since 2014) is a pain. There's also a registry hack marking your OS as an embedded POS system, to get the last security updates until 2019. If anyone has any tips let me know.
I'm almost ready to ditch supporting this OS.
-
Jan 14th, 2018, 12:26 PM
#4
Re: cDownload on Vista (vbRichClient5)
Thanks!
-
Jan 29th, 2018, 04:48 AM
#5
Re: cDownload on Vista (vbRichClient5)
using the WInHttp-5.1 Object as in your example
Crashes if there is no internet connection at line
Code:
If Not http.WaitForResponse(5) Then
"0x80072EE7 -2147012889 ERROR_INTERNET_NAME_NOT_RESOLVED The server name could not be resolved."
Last edited by reexre; Jan 29th, 2018 at 05:02 AM.
-
Jan 29th, 2018, 05:31 AM
#6
Re: cDownload on Vista (vbRichClient5)
Then either check if there is an internet connection before calling the code or trap the error.
-
Jan 29th, 2018, 05:55 AM
#7
Re: cDownload on Vista (vbRichClient5)
Originally Posted by Arnoutdv
Then either check if there is an internet connection before calling the code or trap the error.
I thought there was another way.
I took your advice.
done
-
Feb 15th, 2018, 02:16 PM
#8
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
I'd like to know if there could be some App-deployment problem using:
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA"
as in this example
instead of using WinHttp-5.1 Object
-
Feb 15th, 2018, 04:29 PM
#9
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
Originally Posted by reexre
instead of using WinHttp-5.1 Object
You also do not need to deploy the WinHttp 5.1..., is there something wrong with it on your end?
Olaf
-
Feb 15th, 2018, 05:06 PM
#10
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
Originally Posted by Schmidt
You also do not need to deploy the WinHttp 5.1..., is there something wrong with it on your end?
Olaf
on Windows7
(before it worked, but today)
Yes gives me error
Error Code -2147012867
while "urlmon" works
Last edited by reexre; Feb 15th, 2018 at 05:16 PM.
-
Feb 15th, 2018, 05:32 PM
#11
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
Originally Posted by reexre
Yes , before it worked, and today it gives me error ( ON WINDOWS 7 )
So I changed the code and used "urlmon" that worked perfectly.
As said - UrlMon works with caching (whilst WinHttp does not) - so, when you check for version-changes by
downloading a file (with a constant name) you've put on the WebServer, you might not detect a version-switch on the client-PC,
when the UrlMon-API has served you the "locally cached" version instead.
And the DownloadHistory2-Routine I've put into post #3 currently only reports "http-Protocol-Errors" directly...
(I'm more used to writing Library-Code, not Application-Code - and thus rarely put "Extra-Error-Handlers" into my Routines,
because catching those, is IMO the responsibility of the App-Code).
To report also "general errors" which could happen directly on the Http-Class-Instance due to:
- ServerName not resolvable
- wrong typed URL
- Internet (or Router) down
- connection-loss due to a "WLAN-hickup" or something
...then you need to wrap the routine (e.g in your timer which does the cyclic polling)
with an additional (normal VB6-) Error-Handler.
I'd still say, that WinHttp is the thing you should use in your scenario.
Olaf
-
Feb 15th, 2018, 06:02 PM
#12
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
About urlmon:
Code:
DownloadFile = URLDownloadToFile(0&, _
sSourceUrl, _
sLocalFile, _
BINDF_GETNEWESTVERSION, _
0&) = ERROR_SUCCESS
For what I understand this flag should download Newest version (overwrite locally cached file)
EDIT: Maybe I have to use DeleteUrlCacheEntry
Using DownloadHistory2
I added
Code:
On Error GoTo HandelError
...
HandelError:
MsgBox "Can't check for updates! " & _
vbCrLf & vbCrLf & "Error: " & Err.Number & vbCrLf & Err.Description, vbOKOnly, "Connection Error !"
It gives me Error Code -2147012867
- ServerName not resolvable
- wrong typed URL
- Internet (or Router) down
- connection-loss due to a "WLAN-hickup" or something
I checked the URL (it's exact the same used on "urlmon")
.... And urlmon works ... so I'd Exclude
- ServerName not resolvable
- wrong typed URL
- Internet (or Router) down
Yes it's strange , becasue DownloadHistory2 at the beginning worked. Now not.
Last edited by reexre; Feb 15th, 2018 at 06:18 PM.
-
Feb 15th, 2018, 06:36 PM
#13
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
Originally Posted by reexre
Yes it's strange , becasue DownloadHistory2 at the beginning worked. Now not.
Not sure how that can happen (perhaps you should show the exact code - and also your URL, so that I can test this myself).
We have WinHttp in use in a whole lot of Apps and Services (on a lot of customer-machines and -servers)
- and it is *very* robust whilst doing its work (also not touching the file-system at all).
As for the URLMon-API - I've read a lot of threads (though in the past, maybe it's better now),
that the "Force New Version"-Flags either had no effect, or caused Mem-Leaks - and of course still cluttered the Download-Cache.
Stuff like it is discussed here, I mean:
https://stackoverflow.com/questions/...n-as-a-service
But as said, perhaps it is better now (the appropriate urlmon.dll should have been updated a lot by MS - even on Win7-systems, because it is used also by the IE),
so if you feel more comfortable with the flat API - and your tests all work nicely (also on XP, in case some of your customers still use it) - why not...
Olaf
-
Feb 16th, 2018, 04:23 AM
#14
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
The code I used is the same of your DownloadHistory2
I made some tests by changing the URL:
I notice:
- WinHttp works with URLs different from "https://miorsoft.github.io/Site......"
- "urlmon" instead works with any URLs
Error is fired at this line
Code:
http.Send
If Not http.WaitForResponse(5) Then
So is it github server that somehow blocks WinHttp ? Only to me ? Can you try DownloadHistory2 with that URL ?
Code:
https://miorsoft.github.io/Site/PhotoModularFX/History.txt
-
Feb 16th, 2018, 04:40 AM
#15
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
some code:
WinHTTP
Code:
Private Function DownloadHistory2() As String
Const url = "https://miorsoft.github.io/Site/PhotoModularFX/History.txt"
' On Error GoTo HandelError
Dim http As New WinHttp.WinHttpRequest
http.Open "GET", url, True
http.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All
http.Option(WinHttpRequestOption_SecureProtocols) = &HA8
http.Send
If Not http.WaitForResponse(5) Then ' timeout-seconds, until we cancel the http-Request
DownloadHistory2 = "TimeOut: " & http.StatusText
Exit Function
End If
If http.Status = 200 Then
DownloadHistory2 = StrConv(http.ResponseBody, vbUnicode)
Else
DownloadHistory2 = "Error: " & http.StatusText
End If
Exit Function
HandelError:
End Function
URLMON
Code:
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" _
Alias "DeleteUrlCacheEntryA" _
(ByVal lpszUrlName As String) As Long
Private Const ERROR_SUCCESS As Long = 0
Private Const BINDF_GETNEWESTVERSION As Long = &H10
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000
Private Function DownloadHistory3() As String
Const url = "https://miorsoft.github.io/Site/PhotoModularFX/History.txt"
Dim handle As Long
Dim SaveTo As String
SaveTo = APP.Path & "\NewHistory.txt"
If DownloadFile(url, SaveTo) Then
handle = FreeFile
Open SaveTo For Input As #handle
DownloadHistory3 = Input$(LOF(handle), handle)
Close #handle
Kill SaveTo
End If
End Function
Public Function DownloadFile(sSourceUrl As String, sLocalFile As String) As Boolean
DeleteUrlCacheEntry sSourceUrl
DownloadFile = URLDownloadToFile(0&, sSourceUrl, sLocalFile, BINDF_GETNEWESTVERSION, 0&) = ERROR_SUCCESS
End Function
-
Feb 16th, 2018, 10:57 AM
#16
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
The workaround with the lowered SSL-requirements is only necessary on XP,
so you should wrap the two lines which do that, with an appropriate condition as e.g.:
Code:
Private Function DownloadHistory2() As String
Const url = "https://miorsoft.github.io/Site/PhotoModularFX/History.txt"
On Error GoTo 1
Dim http As New WinHttp.WinHttpRequest
http.Open "GET", url, False
If Not New_c.IsVistaPlus Then '<- lower the SSL-requirements only for XP
http.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All
http.Option(WinHttpRequestOption_SecureProtocols) = &HA8
End If
http.Send
If Not http.WaitForResponse(5) Then ' timeout-seconds, until we cancel the http-Request
DownloadHistory2 = "TimeOut: " & http.StatusText
Exit Function
End If
If http.Status = 200 Then
DownloadHistory2 = StrConv(http.ResponseBody, vbUnicode)
Else
DownloadHistory2 = "Error: " & http.StatusText
End If
1 If Err Then DownloadHistory2 = "Error: " & Err.Description
End Function
Olaf
-
Feb 16th, 2018, 12:13 PM
#17
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
thanks Olaf... but still in trouble.
Before the error was -2147012867
Now, with your last Olaf function (above) the error is:
Error: Errore nel supporto per il canale di protezione
-2147012739
(an error occurred in secure channel support)
raised by Send
by the way , I suppose these errors happen only to me... to you it works, right?
WINDOWS7
Last edited by reexre; Feb 16th, 2018 at 12:38 PM.
-
Feb 16th, 2018, 12:47 PM
#18
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
I FOUND SOLUTION !!!
https://support.microsoft.com/en-us/...e-protocols-in
Using the Easy Fix
Now I had another question:
Once user find an update
How to download it from a link (https://miorsoft.github.io/Site/Phot...oModularFX.zip) using winhttp ?
EDIT:
I got it:
Code:
If http.Status = 200 Then
F = FreeFile
Open sLocalFile For Binary Access Write As F
Put #F, , http.ResponseBody
Close F
DownloadFile = True
Else
Last edited by reexre; Feb 16th, 2018 at 05:31 PM.
-
Feb 23rd, 2018, 06:36 AM
#19
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
noooo
on vista it gives error - -2147012721 "Protecion Error"
using last DownloadHistory2 Post#16
Please can someone download the ZIP and test by pressing "U" button ? Please
Last edited by reexre; Feb 23rd, 2018 at 08:30 AM.
-
Feb 23rd, 2018, 07:40 AM
#20
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
Originally Posted by reexre
on vista it gives error - -2147012721 "Protecion Error"
That's just another SSL-error (probably coming from an un-maintained, IE-wise not updated machine).
Well, you can try to move:
Code:
http.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All
...out of the "XP-specific" conditional block - and place it before the If-condition
(since it's really only the second SSL-specific setting, which makes problems on newer systems IIRC).
That said, ... in your shoes - for the few unmaintained machines where these https-requests might "still fail",
I'd simply "count" the errors - and store the counter somewhere in a DB - and after more than 10 failed
attempts or so, I would show a Message on startup (that this machine is "unable to check for newer versions"
(due to "non-up-to-date SSL-libs" on the system in question).
The easiest way to update the SSL-stuff for such systems is IMO, to upgrade to IE11 (at least for Win7-machines).
For Vista- or XP-machines they will have to find a servicepack (like you did already).
Olaf
-
Feb 23rd, 2018, 08:19 AM
#21
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
@Olaf
on vista
with http.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All
Same error
-2147012721
adding even
http.Option(WinHttpRequestOption_SecureProtocols) = &HA8
error
-2147012867
-
Feb 23rd, 2018, 08:32 AM
#22
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
@Olaf
on vista
with http.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All
Same error
-2147012721
0x80072F8F -2147012721 ERROR_INTERNET_SECURE_FAILURE ErrorClockWrong One or more errors were found in the Secure Sockets Layer (SSL) certificate sent by the server.
adding even
http.Option(WinHttpRequestOption_SecureProtocols) = &HA8
error
-2147012867
0x80072EFD -2147012867 ERROR_INTERNET_CANNOT_CONNECT The attempt to connect to the server failed.
-
Feb 24th, 2018, 12:18 AM
#23
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
Originally Posted by reexre
@Olaf
on vista
with http.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All
Same error
-2147012721
0x80072F8F -2147012721 ERROR_INTERNET_SECURE_FAILURE ErrorClockWrong One or more errors were found in the Secure Sockets Layer (SSL) certificate sent by the server.
Yes, that ErrorClockWrong -thingy is mentioned quite often (when you google for it), with regards to Vista-machines
(which compare the time-frame-validity of a given SSL-cert wrongly).
What I'm wondering is, why you don't avoid SSL-based https requests altogether (for the transfer of a simple Version- and Release-Info-file) -
and just go with "direct http-requests".
Whilst GitHub may always "force" an automatic https-based redirect, your own server (which you have IIRC, or could easily "rent" for a small fee per month),
would not do so - so why not:
- place the little file you want to transfer on your own WebServer
- then performing these "cyclic version-checks" over http (using a new URL, which points to the proper place on your WebServer)
Olaf
-
Feb 28th, 2018, 01:49 PM
#24
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
Originally Posted by reexre
....
-
Mar 1st, 2018, 01:16 PM
#25
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
I've now done that - and it seems to work as it should (reporting the Version-Number)...
Not sure though, what you were trying to accomplish with that test...
Olaf
-
Mar 1st, 2018, 03:46 PM
#26
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
I wanted to know if in general (for most users) it worked.
however, I came back, and for now, clicking the "U" button simply opens the web page. then user can visually check if he has the most up-to-date version.
Last edited by reexre; Mar 1st, 2018 at 04:03 PM.
-
Mar 21st, 2018, 07:37 AM
#27
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
@Olaf
Do you think it is possible that I get some problem using your VB6 Simple Async-Download-Ctl for multiple Files
to download from HTTPS ?
I'm focusing on using it
Last edited by reexre; Mar 21st, 2018 at 01:45 PM.
-
Mar 23rd, 2018, 05:40 AM
#28
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
WARNING!
this question drove me crazy
the main problem seems to be the url from which you want to download
now, using AsyncRead, I noticed that:
this url does not work https://miorsoft.github.io/Site/Phot...oModularFX.zip
while this works https://raw.githubusercontent.com/mi...oModularFX.zip
... it seems to me that the above url also works with WinHttp.WinHttpRequest
So for all those who want to download files from GITHUB I suggest using the RAW URL:
https://raw.githubusercontent.com/......../
-
Mar 23rd, 2018, 05:18 PM
#29
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
https on github.io is using TLS 1.2 only while raw.githubusercontent.com still supports TLS 1.0, 1.1 and 1.2 but this might change in the future too.
Apparently github switched off the old protocols for some of their online properties on 23 Feb this year: https://blog.github.com/2018-02-23-w...dards-removed/
cheers,
</wqw>
-
Mar 24th, 2018, 10:46 AM
#30
Re: [RESOLVED] cDownload on Vista (vbRichClient5)
Originally Posted by reexre
Do you think it is possible that I get some problem using your VB6 Simple Async-Download-Ctl for multiple Files
to download from HTTPS ?
VBs built-in (UserControl-)AsyncRead-functionality is using the same (caching)-APIs under the covers,
as the RC5-Classes cDownloads and cDownload.
RC5.cDownloads can be declared WithEvents, and will then allow you to start and monitor "multiple downloads" as well...
(then allowing, to implement something similar as the UserControl-based "MultiDownload-List" in a cwVList or some
other Widgets, in case you prefer these kind of Controls in your already mostly "Widget-based" App)...
As for the https-stuff - this could always fail on "older, not up-to-date Win-Systems" (for the reasons wqweto now pointed out as well).
GitHub might change to newer TLS-algos in its serverside certificates at any time (also on the "Raw-URLs") -
so, as said... to be on the safe side, you should consider "renting your own WebSite" for a small monthly fee,
to have more control over either:
- plain http-calls (which you do not force into a clientside-redirect, based on https)
- or your own certificates which you use to enable https-requests on your site
Olaf
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|