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

AutoUpdate for VB.NET

Rate me:
Please Sign up or sign in to vote.
3.31/5 (8 votes)
1 May 2008CPOL1 min read 78.9K   3.8K   32   32
This is a DLL library to check for updates for your application.

Introduction

You can use this library for checking for updates for your application. It's simple and small (only one function). The update package must be a zip file.

Using the Code

The DLL only contains one function: CheckForUpdates in the AutoUpdate namespace.

It has the following arguments:

  • NewestVersionLocation As String - This is the file location on the Internet where your newest version is placed, in plaintext. The file can only contain, for example: 2.0.
    You can use a *.txt file for this, but any extension is possible.
  • NewestVersionDownloadLocation As String - This is the file location on the Internet where your newest application (files) are stored in a zip file.
  • UnzipDir As String - This is the directory where the files must be extracted. If you use an empty string, or you omit this argument, the startup path of the application is used.
  • DisplayWindow As Boolean - With this, you can choose to display the download window or not.
  • MsgBoxText As String - This is the message displayed in a MsgBox if there is an update available.
  • MsgBoxTitle As String - This is the title of that MsgBox.

For the source code, download the zip file above, it has comments on my own written code.

Using an empty string for the last four arguments means the same as omitting them.

Example to Use

VB.NET
AutoUpdate.CheckForUpdates(http://yourdomain.com/versions/app.txt, _
    "http://yourdomain.com/update_downloads/app.zip", "", True, _
    "Newer version available. Download it?", "")

References

History

  • 1st May, 2008: Initial post

License

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


Written By
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralAutoUpdate-2 Pin
bhogsett13-Feb-10 3:05
bhogsett13-Feb-10 3:05 
I have implemented AutoUpdate in a project on which I am working and
thought I would share the implementation and changes I made to the AutoUpdate.dll.
Pimb's program is excellent and by having the source I
could hack on it. Thanks Pimb. I even learned a little Dutch!


In my application I need to download the executable that is running when AutoUpdate is first called.
Pimb showed how to do that in an earlier post. But I didn't want to close the application until after AutoUpdate had
determined that there was in fact an update. After the update is complete, I also wanted to give the user the option to restart the newly updated application.

I have created two zip files. One has the source and my diffs and the other has two projects. I cannot figure out how to upload the files! Now that should inspire a lot of confidence. Smile | :) As soon as I do I will upload them. Pimb I am sending them to you in an e-mail.

The Autoupdate project is my revised AutoUpdate. The substantive changes are to move the code to kill the process that will be updated into AutoUpdate and to ask if the user wants to restart after the update. I also compiled with strict on so that I needed to cleanup some declartions and one typo. While doing this I inserted the new Ionic.Zip.dll that now uses a different name and namespace.

The Updater project is the console application that calls AutoUpdate and it in turn is called by the program being updated. As Pimb said earlier this must be a console application. The program takes two arguments the name of the process being updated (calling process) and the name of the program which can be used in dialogs. Both the process and program
are now optional parameters to AutoUpdate.CheckForUpdates. If the user doesn't want to kill a process or use a product name then just not pass the arguments in to AutoUpdate.CheckForUpdates.

I think it might be helpful to show how I use all this.

In my main application I have a menu item--Check for updates--which is handled like this:

Private Sub CheckForUpdateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckForUpdateToolStripMenuItem.Click
        ' http://dotnetperls.com/process-start-examples-vbnet
        ' New ProcessStartInfo create
        Dim p As New ProcessStartInfo
        ' Specify the location of the binary
        p.FileName = "UpDater.exe" 'This is the console application that calls the AutoUpdate 
        ' Use these arguments for the process
        p.Arguments = Process.GetCurrentProcess.ProcessName & " " & ProductName
        ' Use a hidden window
        p.WindowStyle = ProcessWindowStyle.Hidden
        ' Start the process
        Process.Start(p)
    End Sub


UpDater.exe is the console application that calls AutoUpdate. My module to create it looks like this:

Module Updater
    Sub Main(ByVal args() As String)
        Dim processName As String = args(0)
        Dim ProductName As String = args(1)
        getupdates(processName, ProductName)
    End Sub
    Sub getupdates(ByVal ProcessName As String, ByVal ProductName As String)
        AutoUpdate.CheckForUpdates( _
        "http://billhogsett.com/wordFrequency/wordFrequencyVersion.txt", _
        "http://billhogsett.com/wordFrequency/wordFrequencyUpdate.zip", "", True, _
        "A new version of " & ProductName & " is available. Download it Now?  " & ControlChars.CrLf & ProductName & _
        " will be closed.", "wordFrequency Updater", ProcessName, ProductName)
    End Sub
End Module


Sorry for the lousy formatting of this message.

Bill
AnswerRe: AutoUpdate-2--The Zip files Pin
bhogsett13-Feb-10 3:22
bhogsett13-Feb-10 3:22 
GeneralRe: AutoUpdate-2--The Zip files Pin
pimb213-Feb-10 3:30
pimb213-Feb-10 3:30 
GeneralRe: AutoUpdate-2--The Zip files Pin
bhogsett13-Feb-10 4:16
bhogsett13-Feb-10 4:16 
GeneralRe: AutoUpdate-2--The Zip files Pin
juan321116-Mar-10 21:48
juan321116-Mar-10 21:48 
GeneralRe: AutoUpdate-2--The Zip files Pin
bhogsett17-Mar-10 2:52
bhogsett17-Mar-10 2:52 
GeneralRe: AutoUpdate-2--The Zip files Pin
juan321117-Mar-10 3:43
juan321117-Mar-10 3:43 
GeneralRe: AutoUpdate-2--The Zip files Pin
bhogsett17-Mar-10 4:41
bhogsett17-Mar-10 4:41 
GeneralRe: AutoUpdate-2--The Zip files Pin
pimb217-Mar-10 5:31
pimb217-Mar-10 5:31 
GeneralRe: AutoUpdate-2--The Zip files Pin
bhogsett17-Mar-10 6:53
bhogsett17-Mar-10 6:53 
GeneralName ' Autoupdate ' is not declared - error Pin
vidhyaej9-Feb-10 17:27
vidhyaej9-Feb-10 17:27 
GeneralRe: Name ' Autoupdate ' is not declared - error Pin
pimb210-Feb-10 8:00
pimb210-Feb-10 8:00 
GeneralRe: Name ' Autoupdate ' is not declared - error Pin
vidhyaej10-Feb-10 23:42
vidhyaej10-Feb-10 23:42 
GeneralRe: Name ' Autoupdate ' is not declared - error Pin
vidhyaej11-Feb-10 1:11
vidhyaej11-Feb-10 1:11 
GeneralRe: Name ' Autoupdate ' is not declared - error Pin
pimb211-Feb-10 4:00
pimb211-Feb-10 4:00 
GeneralRe: Name ' Autoupdate ' is not declared - error Pin
vidhyaej12-Feb-10 17:50
vidhyaej12-Feb-10 17:50 
GeneralRe: Name ' Autoupdate ' is not declared - error Pin
pimb213-Feb-10 0:29
pimb213-Feb-10 0:29 
GeneralRe: Name ' Autoupdate ' is not declared - error Pin
vidhyaej15-Feb-10 18:26
vidhyaej15-Feb-10 18:26 
GeneralRe: Name ' Autoupdate ' is not declared - error Pin
pimb216-Feb-10 9:53
pimb216-Feb-10 9:53 
General'Ionic.Utils.Zip.ZipFile' is not defined Pin
vidhyaej7-Feb-10 19:12
vidhyaej7-Feb-10 19:12 
GeneralRe: 'Ionic.Utils.Zip.ZipFile' is not defined Pin
pimb27-Feb-10 19:42
pimb27-Feb-10 19:42 
QuestionAbout the updater Pin
MatthewAuld23-Apr-09 23:05
MatthewAuld23-Apr-09 23:05 
AnswerRe: About the updater Pin
pimb224-Apr-09 4:37
pimb224-Apr-09 4:37 
AnswerRe: About the updater Pin
MatthewAuld25-Apr-09 20:58
MatthewAuld25-Apr-09 20:58 
QuestionAn example? Pin
davistv22-Jun-08 22:19
davistv22-Jun-08 22:19 

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.