Click here to Skip to main content
6,597,576 members and growing! (19,965 online)
Email Password   helpLost your password?
Languages » VB.NET » Applications     Intermediate License: The Code Project Open License (CPOL)

Application Auto Update Revisited

By Eduardo Oliveira

An article on updating Windows applications through the web.
VB, Windows, .NET 2.0VS2005, Dev
Posted:19 Nov 2006
Views:57,159
Bookmarked:122 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
16 votes for this article.
Popularity: 5.61 Rating: 4.66 out of 5

1

2
1 vote, 6.3%
3
1 vote, 6.3%
4
14 votes, 87.5%
5

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.

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)

About the Author

Eduardo Oliveira


Member
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/Sybase, developing Client/Server applications and ASP.NET server controls for CMS.
Occupation: Web Developer
Location: Canada Canada

Other popular VB.NET articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 25 of 39 (Total in Forum: 39) (Refresh)FirstPrevNext
GeneralThe process cannot access the file because it is being used by another process PinmemberNgonidzashe Munyikwa3:32 24 Jul '09  
GeneralRe: The process cannot access the file because it is being used by another process PinmemberNgonidzashe Munyikwa21:26 25 Jul '09  
GeneralRe: The process cannot access the file because it is being used by another process PinmemberEduardo Oliveira13:27 26 Jul '09  
GeneralC# If AutoUpdate.UpdateFiles() Then Exit Sub PinmemberLoots3:52 19 Mar '09  
GeneralRe: C# If AutoUpdate.UpdateFiles() Then Exit Sub PinmemberAuspexPT0:22 1 Apr '09  
GeneralIs there a C# version? PinmemberVisual Tracker4:35 22 Jan '09  
General[Message Deleted] PinmemberSebastian Diaz10:16 2 Oct '08  
GeneralRe: Consulta Pinmemberzitun6:11 7 Oct '08  
GeneralVB error with this code (VS2008) Pinmembern3mesis1257:46 26 Sep '08  
QuestionRe: VB error with this code (VS2008) Pinmembern3mesis1257:49 26 Sep '08  
GeneralVB.NET saving and retrieving word file into sql database Pinmembernaresh150723:56 2 Sep '08  
GeneralVB.NET saving and retrieving word file into sql database Pinmembernaresh150723:55 2 Sep '08  
GeneralHow does the module handling DLL references of the software? PinmemberS. Kolic3:22 4 May '08  
Generaldoes in work if your app has been initially installed via an MSI? Pinmemberewart18:31 14 Mar '08  
GeneralWhy not update the AutoUpdate program ? Pinmembercliftonarms13:08 28 Feb '08  
GeneralC# v.2.1.1 (with some improvements and an example of use) PinmemberTiago Freitas Leal15:32 7 Feb '08  
GeneralRe: C# v.2.1.1 (with some improvements and an example of use) Pinmembermayaolong18:46 1 Mar '08  
GeneralRe: C# v.2.1.1 (with some improvements and an example of use) Pinmemberkingna23:11 20 Nov '08  
GeneralRe: C# v.2.1.1 (with some improvements and an example of use) Pinmemberkingna21:59 21 Nov '08  
QuestionRe: C# v.2.1.1 (with some improvements and an example of use) Pinmembergwenny20:36 3 Jun '09  
AnswerRe: C# v.2.1.1 (with some improvements and an example of use) PinmemberTiago Freitas Leal13:43 5 Jun '09  
GeneralRe: C# v.2.1.1 (with some improvements and an example of use) Pinmemberc95se5m9:21 14 Aug '09  
GeneralDownload not accessible :( [modified] PinmembertwisterPB6519:59 6 Dec '07  
GeneralRe: Download not accessible :( [modified] PinmembertwisterPB6522:09 9 Dec '07  
GeneralGreat Code PinmemberAust Paul0:18 25 Nov '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 19 Nov 2006
Editor: Smitha Vijayan
Copyright 2006 by Eduardo Oliveira
Everything else Copyright © CodeProject, 1999-2009
Web16 | Advertise on the Code Project