Click here to Skip to main content
15,350,410 members
Articles / Programming Languages / Visual Basic
Posted 19 Nov 2006


187 bookmarked

Application Auto Update Revisited

Rate me:
Please Sign up or sign in to vote.
4.84/5 (23 votes)
19 Nov 2006CPOL2 min read
An article on updating Windows applications through the web.


Since my first iteration of the AutoUpdate, I noticed that I don't really need the ability to change the AutoUpdate program itself, so I don't need it. The second thing is that most of the time I don't need to update all the files.

What has changed

The AutoUpdate program (AutoUpdate.exe) is no longer required. Now, everything that is needed is in the DLL (AutoUpdate.dll). No need to touch the CommandLine anymore since everything is at the same place. The AutoUpdate doesn't need to be a class, now it is just a module, so, no need to create an AutoUpdate variable.

No need to change the AutoUpdate code. The remote path, the update file name, and the error message are now properties and the last two have default values.

The update file has a new layout, as shown:

<File Name>;<Version>   [' comments    ]
<File Name>[;<Version>] [' comments    ]

<File Name>[;?]         [' comments    ]
<File Name>[;delete]    [' comments    ]

And this is what it means:

  • Blank lines and comments are ignored.
  • The first line should be the current program/version.
  • From the second line to the end, the second parameter is optional.
  • If the second parameter is not specified, the file is updated.
  • If the version is specified, the update checks the version.
  • If the second parameter is an interrogation mark (?), the update checks if the file already exists, and "doesn't" upgrade if it exists.
  • If the second parameter is "delete", the system tries to delete the file.
  • "'" (chr(39)) starts a line comment (like VB).

The UpdateFiles function returns True if the AutoUpdate did the update or there was an error during the update, or False if nothing was done.

The auto update web folder

Some things never change. The auto update web folder should have a folder for each system you want to upgrade. The root folder is the one that you will refer on the RemotePath variable. Each sub folder should be named as the assembly name (normally, the program name without the extension). Inside the program folder, you save the files that you want to update and the file Update.txt (or the name that you defined in the UpdateFileName property) with the layout explained above.

Using the code

You can add the module to your project, or you can add a reference to the DLL. After that, you just need to call the UpdateFiles function. You also can change the default properties before the call.

Public Sub Main()
    ' You can set some parameters thru properties
    ' The remote path can be set thru the RemotePath property or 
    ' thru the RemotePath parameter in the function call
    ' UpdateFileName and ErrorMessages have default value so it's optional
    AutoUpdate.RemotePath = ""

    ' the final location to the files will be RemotePath + AssembyName + "/" + FileName
    ' ex:

    AutoUpdate.UpdateFileName = "MyUpdate.dat"
    AutoUpdate.ErrorMessage = "Something funny is going on trying to auto update."

    ' test if an update is needed and quit the program if so.
    If AutoUpdate.UpdateFiles() Then Exit Sub

    ' here goes your regular code in the main sub
    Application.Run(New Form1)
End Sub

What else can be done

In the server side, you can build a service that automatically generates the update file, but this is up to you!


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Eduardo Oliveira
Software Developer (Senior)
Canada Canada
Eduardo Oliveira graduated in Computer Systems Analysis in Rio de Janeiro - Brazil in 1990.
He has been working as Programmer Analyst since.
In 2001 immigrated to Canada and today lives in Calgary and works with .NET and SQL server, developing desktop and web applications.

Comments and Discussions

QuestionUpdate.txt example Pin
Host Master NSMEDIA31-Oct-21 21:01
MemberHost Master NSMEDIA31-Oct-21 21:01 
Questionautoupdate service Pin
crosemffet3-Sep-14 14:04
Membercrosemffet3-Sep-14 14:04 
Questionthanks for sharing Pin
Southmountain15-Jun-12 12:53
MemberSouthmountain15-Jun-12 12:53 
Generalupdated infoParam = "?" with a CompareFiles function Pin
creativesoul26-Feb-10 4:39
Membercreativesoul26-Feb-10 4:39 
QuestionAnyone having issues using this with VISTA platform Pin
Kebrite8-Feb-10 8:00
MemberKebrite8-Feb-10 8:00 
GeneralEnvironment.Exit(0) Pin
timjf26-Dec-09 14:16
Membertimjf26-Dec-09 14:16 
GeneralRe: Environment.Exit(0) Pin
keno2oo111-Sep-12 20:32
Memberkeno2oo111-Sep-12 20:32 
GeneralRe: Environment.Exit(0) Pin
keno2oo115-Sep-12 5:18
Memberkeno2oo115-Sep-12 5:18 
GeneralI am lost on how to use this PLEASE HELP! Pin
Gaby Bitar17-Dec-09 2:46
MemberGaby Bitar17-Dec-09 2:46 
GeneralAutoUpdate with Download Form and Progress Pin
ammar7913-Dec-09 5:23
Memberammar7913-Dec-09 5:23 
GeneralRe: AutoUpdate with Download Form and Progress [modified] Pin
KyferEz8-Nov-10 10:50
MemberKyferEz8-Nov-10 10:50 
GeneralRe: AutoUpdate with Download Form and Progress Pin
kyoshirian14-Jul-19 22:06
Memberkyoshirian14-Jul-19 22:06 
GeneralThe process cannot access the file because it is being used by another process Pin
Ngonidzashe Munyikwa24-Jul-09 2:32
MemberNgonidzashe Munyikwa24-Jul-09 2:32 
GeneralRe: The process cannot access the file because it is being used by another process Pin
Ngonidzashe Munyikwa25-Jul-09 20:26
MemberNgonidzashe Munyikwa25-Jul-09 20:26 
GeneralRe: The process cannot access the file because it is being used by another process Pin
Eduardo Oliveira26-Jul-09 12:27
professionalEduardo Oliveira26-Jul-09 12:27 
GeneralC# If AutoUpdate.UpdateFiles() Then Exit Sub Pin
Loots19-Mar-09 2:52
MemberLoots19-Mar-09 2:52 
GeneralRe: C# If AutoUpdate.UpdateFiles() Then Exit Sub Pin
AuspexPT31-Mar-09 23:22
MemberAuspexPT31-Mar-09 23:22 
QuestionIs there a C# version? Pin
Visual Tracker22-Jan-09 3:35
MemberVisual Tracker22-Jan-09 3:35 
General[Message Deleted] Pin
Sebastian Diaz2-Oct-08 9:16
MemberSebastian Diaz2-Oct-08 9:16 
GeneralRe: Consulta Pin
zitun7-Oct-08 5:11
Memberzitun7-Oct-08 5:11 
GeneralVB error with this code (VS2008) Pin
n3mesis12526-Sep-08 6:46
Membern3mesis12526-Sep-08 6:46 
QuestionRe: VB error with this code (VS2008) Pin
n3mesis12526-Sep-08 6:49
Membern3mesis12526-Sep-08 6:49 
GeneralVB.NET saving and retrieving word file into sql database Pin
naresh15072-Sep-08 22:56
Membernaresh15072-Sep-08 22:56 
GeneralVB.NET saving and retrieving word file into sql database Pin
naresh15072-Sep-08 22:55
Membernaresh15072-Sep-08 22:55 
QuestionHow does the module handling DLL references of the software? Pin
S. Kolic4-May-08 2:22
MemberS. Kolic4-May-08 2:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.