-
Try this...
To start with, we will build our simple updater program. It needs to do the following tasks in order to work properly:
Open the local version file and read in the number
Download the server version file and save it in a temporary file on the local computer.
Open the server version file and read in the number
Compare the version numbers from the server and the local computer.
If the server number is larger than the local computer number, announce to the user that a new version of the program exists. Ask the user if they want to download an update.
If the user clicks no, exit the program.
Else (!) download the latest version of the program from the server and overwrite the local computer copy.
Update the local version file with the number from the server version file.
Announce to the user that the update was a success!
Code
Create a new project, with one form. Add a command button onto the form with the Caption "Check for Updates" and the name, "cmdUpdate". Right-click the toolbox and select "Components". From the list of controls, tick the box next to "Microsoft Internet Transfer Control". An icon will appear in the toolbox:
Click on this icon, and add the Internet Transfer control to the form. Rename it "InetUpdate"
OK! Now, add the following code to the cmdUpdate_Click event:
---- Start Code ----
Dim intLocalVer As Integer
Dim b() As Byte
Dim intRemoteVer As Integer
Dim strRemoteVer As String
Dim doUpdate As Boolean
'1. Open the local version file and read in the number
Open App.Path & "\curversion.dat" For Input As #1
intLocalVer = CInt(Input(LOF(1), 1))
Close 1
'2. Download the remote version file and read in the number
' Note: This is all one line:
b() = InetUpdate.OpenURL("http://visualbasic.about.com/
library/weekly/remotever.dat", 1)
strRemoteVer = ""
For t = 0 To UBound(b)
strRemoteVer = strRemoteVer + Chr(b(t))
Next
intRemoteVer = Int(strRemoteVer)
'3. Compare numbers
If intRemoteVer > intLocalVer Then
'Note: This is all one line:
If MsgBox("A more recent version of this program
exists. Would you like to update it now?", vbYesNo Or vbQuestion) = vbYes Then
doUpdate = True
Else
doUpdate = False
End If
Else
MsgBox "You already have the most recent version of this program."
doUpdate = False
End If
'4. If doupdate = True, then download the latest program exe from the site
If doUpdate Then
'Note: This is all one line:
b() = InetUpdate.OpenURL("http://visualbasic.about.com/
library/weekly/update.exe", 1)
Open App.Path & "\update.exe" For Binary Access Write As #1
Put #1, , b()
Close 1
Kill App.Path & "\program.exe"
Name App.Path & "\update.exe" As App.Path & "\program.exe"
'Now save the current version into the local version file
Open App.Path & "\curversion.dat" For Output As #1
Print #1, strRemoteVer
Close 1
MsgBox "Update Complete!"
End If
--- End Code ---
Testing...
-
Thanks CyberCarsten,
I haven't tried your code yet, but I will soon!
Christophe
-
Hi there,
I'm working on an application that will be distributed on CD-ROM. But I want to start, next year, distributing it over the internet. (Is there really any point of a user having to go into a shop, buy a CD - which you have to spend a rake of dosh on packaging and cutting the CDS, when they can simply download it in the first place?)
But anyway, what I want to know is, does anybody have an idea how users can download an update to my program - a small but progressive change to some of the forms, without them having to download the entire exe again? Maybe you don't have a precise answer, but I'd be grateful if you could tell me where to start looking for information on this issue.
Thanks for any help!