-
This is somthing I dont understand... Say I have a program that searches the web, and one day while using it, I find out a search engine that it uses is offline for good. So I want to release a patch to update it, but how can I make a patch that goes into my .exe and replaces the old form with the new form in my patch? I dont see how I can update an .exe
-
just send a new EXE, cause they already have all of the runtime files, so just send them a new EXE
-
I found this article on about.com.
Code:
Creating an auto update function
Dateline: 03/10/99
Introduction
For those readers who are running Windows 98, you may have noticed that whenever you try to install a new piece of hardware, the operating system dials into the Microsoft server to try and download the very latest version. In this article, I will show you how to use the Microsoft Internet controls to build in an Auto Update feature into your own applications.
The Principle
The idea is that there will be a command button or menu item within your program that the user can use to check for the latest version of the program on a web server. This command button will run an external "updater" program, that will dial-in to the web server and download a current version file, that contains the version number of the very latest program. If the program finds a more recent version than the one installed, it will attempt to download the updated files. For the purposes of demonstration, I have create a very simple program that will display its version information in a message box whenever it is run. Another program, which we will build in this article, will act as an updater, checking the web server for an updated version of the file whenever it is run.
Technical Ideas
In theory, you should be able to keep a text file on the Internet that contains information about the current version of your program. On the local computer, you will also keep a similar file with information about the current version installed. The Update program will compare the two files, and if a more recent version of the program exists online, it will download the program and overwrite the older version.
Downloading files using the Internet Transfer Control
Along with VB5 came an extra control called the Internet Transfer Control. This handy ActiveX can be used to connect to a certain web server and download files. In this case, we will use it to download the current version text file.
Structure of the version text file
Each version file will contain a number that corresponds to the version of the program. For example, version 1.0 of a program might have the number "000001" or even "1000" in the file. For the purposes of this article, this is all that there is in this file, although you may wish to include lists of files, each with its own version number.
Let's Go!
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 ---
-
Why did you use the code format to put the text that wasn't part of the code? now to respond I have to go way thehell over here, and I have my start menu on auto hide, so it pops up over everything If I get close enough... I think the code feature shouldn't be on here... is there a way to turn it off on my viewing?
-
There is no way to turn it off. I'm sorry, I did not know the code would do that. I just copied and pasted it. It is not my fault. I don't think John can do anything about it either. Sorry!