Click here to Skip to main content
15,905,616 members
Articles / Programming Languages / Visual Basic
Article

Application Auto Update Revisited

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

Introduction

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.

VB
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 = "http://www.url.com/directory/"

    ' the final location to the files will be RemotePath + AssembyName + "/" + FileName
    ' ex: http://www.url.com/directory/AutoUpdateTest/MyUpdate.dat

    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!

License

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


Written By
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

 
Questiondoes in work if your app has been initially installed via an MSI? Pin
ewart14-Mar-08 17:31
ewart14-Mar-08 17:31 
QuestionWhy not update the AutoUpdate program ? Pin
cliftonarms28-Feb-08 12:08
cliftonarms28-Feb-08 12:08 
GeneralC# v.2.1.1 (with some improvements and an example of use) [modified] PinPopular
Tiago Freitas Leal7-Feb-08 14:32
professionalTiago Freitas Leal7-Feb-08 14:32 
GeneralRe: C# v.2.1.1 (with some improvements and an example of use) Pin
mayaolong1-Mar-08 17:46
mayaolong1-Mar-08 17:46 
GeneralRe: C# v.2.1.1 (with some improvements and an example of use) Pin
Nate Liu20-Nov-08 22:11
Nate Liu20-Nov-08 22:11 
GeneralRe: C# v.2.1.1 (with some improvements and an example of use) Pin
Nate Liu21-Nov-08 20:59
Nate Liu21-Nov-08 20:59 
QuestionRe: C# v.2.1.1 (with some improvements and an example of use) Pin
gwenny3-Jun-09 19:36
gwenny3-Jun-09 19:36 
AnswerRe: C# v.2.1.1 (with some improvements and an example of use) Pin
Tiago Freitas Leal5-Jun-09 12:43
professionalTiago Freitas Leal5-Jun-09 12:43 
I suggest you try the code. Refering your use case - starting the update process per server request, this is a completely different scenario. Auto update isn't suited for that scenario - as its name says, auto update means "I update myself".
GeneralRe: C# v.2.1.1 (with some improvements and an example of use) Pin
c95se5m14-Aug-09 8:21
c95se5m14-Aug-09 8:21 
GeneralRe: C# v.2.1.1 (with some improvements and an example of use) Pin
Jasmine Pomelo11-Nov-09 18:14
Jasmine Pomelo11-Nov-09 18:14 
GeneralRe: C# v.2.1.1 (with some improvements and an example of use) Pin
Tiago Freitas Leal12-Nov-09 10:16
professionalTiago Freitas Leal12-Nov-09 10:16 
GeneralRe: C# v.2.1.1 (with some improvements and an example of use) Pin
tdata16-Nov-09 0:24
tdata16-Nov-09 0:24 
GeneralRe: C# v.2.1.1 (with some improvements and an example of use) Pin
omzig26-Mar-10 9:59
omzig26-Mar-10 9:59 
GeneralRe: C# v.2.1.1 (with some improvements and an example of use) Pin
KyferEz9-Nov-10 11:56
KyferEz9-Nov-10 11:56 
GeneralRe: C# v.2.1.1 (with some improvements and an example of use) Pin
KyferEz8-Nov-10 18:35
KyferEz8-Nov-10 18:35 
QuestionRe: Need urgent reply (C# v.2.1.1 (with some improvements and an example of use)) Pin
pranpara26-Nov-10 2:38
pranpara26-Nov-10 2:38 
GeneralRe: C# v.2.1.1 (with some improvements and an example of use) [modified] Pin
hitbraga25-Jan-19 0:06
hitbraga25-Jan-19 0:06 
GeneralDownload not accessible :( [modified] Pin
twisterPB656-Dec-07 18:59
twisterPB656-Dec-07 18:59 
GeneralRe: Download not accessible :( [modified] Pin
twisterPB659-Dec-07 21:09
twisterPB659-Dec-07 21:09 
GeneralGreat Code Pin
Aust Paul24-Nov-07 23:18
Aust Paul24-Nov-07 23:18 
Question404 Error Pin
Mike Fed12-Oct-07 10:19
Mike Fed12-Oct-07 10:19 
AnswerRe: 404 Error Pin
Member 454583129-Aug-08 14:21
Member 454583129-Aug-08 14:21 
GeneralUpdating a BHO Pin
jorgito_rubio18-Sep-07 7:51
jorgito_rubio18-Sep-07 7:51 
GeneralRe: Updating a BHO Pin
dta43168-Feb-10 17:39
dta43168-Feb-10 17:39 
QuestionPlease Help Pin
jerrywade12-Jul-07 6:55
jerrywade12-Jul-07 6:55 

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.