Version and download

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I put the lastest version on my form on a web site. I want a VBscript that
can look up which version of form the user is using and if it's not the
lastest version I want to download automatically from the web site.
I want something like:
If item.formdescription.version <> "15.4" then
Download
End if
thanks,
Josianne
 
Well, you already have the version test there. Now you just need the code to
download your form.

Use something like this:

Set objIEApp = CreateObject("InternetExplorer.Application")
objIEApp.Navigate strUpdateURL
objIEApp.Visible = True

That would display the download page called for in the strUpdateURL string
(www.something.com/files/download.htm). If you changed that URL string to a
an executable link such as www.something.com/files/download.exe then the
download would run automatically if it's in something like an installer
package.

If you wanted to use code to download say an OFT file then you could use
something like this:

Call DownloadFileAndClearCache(strUpdateXML, strLocalFileName) where the
update URL string has the file location and the second argument has the
download file name and path.

That procedure is courtesy of one of the VB MVP's, Randy Birch:

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 Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal nLength As Long)

Private Const ERROR_SUCCESS As Long = 0
Private Const BINDF_GETNEWESTVERSION As Long = &H10
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2005 VBnet, Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
' applications, but you may not reproduce
' or publish this code on any web site,
' online service, or distribute as source
' on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub DownloadFileAndClearCache(sSourceUrl As String, sLocalFile As
String)
Dim hfile As Long

On Error Resume Next

'Attempt to delete any cached version of
'the file. Since we're only interested in
'nuking the file, the routine is called as
'a sub. If the return value is requires
'(calling as a function), DeleteUrlCacheEntry
'returns 1 if successful, or 0 otherwise, e.g.
' If DeleteUrlCacheEntry(sourceUrl) = 1 Then
' Debug.Print "cached file found and deleted"
' Else
' Debug.Print "no cached file for " & sourceUrl
' End If
'Note that the remote URL is passed as this is the
'name the cached file is known by. This does NOT
'delete the file from the remote server.
Call DeleteUrlCacheEntry(sSourceUrl)

If DownloadFile(sSourceUrl, sLocalFile) = True Then
'hfile = FreeFile
'Open sLocalFile For Input As #hfile
'Text1.Text = Input$(LOF(hfile), hfile)
'Close #hfile
End If
End Sub


Private Function DownloadFile(sSourceUrl As String, _
sLocalFile As String) As Boolean

On Error Resume Next

'Download the file. BINDF_GETNEWESTVERSION forces
'the API to download from the specified source.
'Passing 0& as dwReserved causes the locally-cached
'copy to be downloaded, if available. If the API
'returns ERROR_SUCCESS (0), DownloadFile returns True.
DownloadFile = URLDownloadToFile(0&, sSourceUrl, _
sLocalFile, BINDF_GETNEWESTVERSION, _
0&) = ERROR_SUCCESS
End Function
 
Back
Top