You are viewing our Forum Archives. To view or take place in current topics click here.
VB.NET Very easy updater
Posted:

VB.NET Very easy updaterPosted:

OmitZz
  • Junior Member
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 68
Reputation Power: 2
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 68
Reputation Power: 2
Hello guys/girls! I will be helping you make a updater for your programs made in VB.NET. Doing this will allow your users to get the latest versions of your program without having to keep up with a forum post or going to a website to see if there is a newer version. Let's get this started.



1. Open up your project/start a new project.
Add a new form for the updater and add a button, 5 labels and a progress bar.
Change the button text to Update or whatever you want and set the Enabled property to False
Your form should look like this
[ Register or Signin to view external links. ]

Before we continue, you should add this to your to the top of your code

Imports System.IO
Imports System.Net


Then add this to your code

Dim locat As String = System.Reflection.Assembly.GetEntryAssembly.Location
    Dim MyDirectory As String = System.IO.Path.GetDirectoryName(locat)
    Public totalsize As String
    Public link As String
    Public Csize As String


You are also going to need to download a file hosting program called Dropbox
[ Register or Signin to view external links. ]

Once you have downloaded Dropbox, you will see a blue box icon in the system tray at the bottom right hand of your screen. Double click the icon then open the 'Public' folder. Then I recommend you make a new folder in the Public folder named after your program to keep track of all of your files.

Once in the folder you will use to store your files, add a new text document named Version and make the text in it 1.0.0.0 and save it. Now right click that file and you should see a Dropbox option with some more options within it. Remember this because you will need to click "Copy Public Link" from that menu later in this tutorial.

2. Add a Timer and a BackgroundWorker to your form. Double click both of them to get the events in your code. Now click on the BackgroundWorker_DoWork and on the top right of the code window click the drop down menu with the text "DoWork" and select "RunWorkerComplete" and double click the form and button to get them in the code as well.

3. Now let's got down to the code. I will make this easy and just post the whole thing now and explain things afterwards.

Imports System.IO
Imports System.Net

Public Class Form1

    Dim locat As String = System.Reflection.Assembly.GetEntryAssembly.Location
    Dim MyDirectory As String = System.IO.Path.GetDirectoryName(locat)
    Public totalsize As String
    Public link As String
    Public Csize As String
    Public amount As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        My.Computer.FileSystem.RenameFile(MyDirectory + "\" + Me.ProductName + ".exe", Me.ProductName + ".old")
        Timer1.Start()
        BackgroundWorker1.RunWorkerAsync()
        Button1.Enabled = False
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If File.Exists(MyDirectory + "\" + Me.ProductName + ".old") Then
            File.Delete(MyDirectory + "\" + Me.ProductName + ".old")
        End If
        Label4.Text = Me.ProductVersion
        Try
            Dim instance As WebClient = New WebClient
            Dim address As String = "[COLOR=#ffff99][B]YOUR VERSION URL[/B][/COLOR]"
            Dim returnValue As String
            returnValue = instance.DownloadString(address)
            Label5.Text = returnValue
            If Label4.Text >= Label5.Text Then
            Else
                Button1.Enabled = True
            End If
        Catch ex As Exception

        End Try
        Control.CheckForIllegalCrossThreadCalls = False
    End Sub

    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
        Try
            link = "[B]YOUR PROGRAM URL[/B]"
            Dim size1 As Integer
            Dim wr As WebRequest
            wr = WebRequest.Create(link)
            Dim webr As WebResponse = wr.GetResponse
            size1 = webr.ContentLength
            webr.Close()
            size1 = size1 / 1024
            ProgressBar1.Maximum = size1
            totalsize = size1
            My.Computer.Network.DownloadFile("[COLOR=#ffff99][B]YOUR PROGRAM URL[/B][/COLOR]", MyDirectory + "\" + Me.ProductName + ".exe")
        Catch ex As Exception

        End Try
    End Sub

    Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
        Try
            Shell(MyDirectory + "\" + Me.ProductName + ".exe")
            Me.Close()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If File.Exists(MyDirectory + "\" + Me.ProductName + ".exe") Then
            Dim o As New FileInfo(MyDirectory + "\" + Me.ProductName + ".exe")
            amount = o.Length
            amount = amount / 1024
            Csize = amount
            ProgressBar1.Value = amount
        End If
        Label1.Text = Csize + " KBs / " + totalsize + " KBs"
    End Sub
End Class


Now go to your Dropbox folder and copy the link and paste it where it says YOUR VERSION URL
As for your program URL, as long as you store your program in the same folder as the version.txt, you can simply modify the version url by replacing the Version.txt with YOURPROGRAM.exe

Here are my URLs
[ Register or Signin to view external links. ]
[ Register or Signin to view external links. ]

Now let's get something straight, this code is for the example form I will provide the source code for in this post. You will probably need to do a few things to get this to work right for your program.

First of all, you will need to add this part of the code to form_load of your main form in your program.

If File.Exists(MyDirectory + "\" + Me.ProductName + ".old") Then
            File.Delete(MyDirectory + "\" + Me.ProductName + ".old")
        End If


Also, on the BackgroundWorker_RunWorkerComplete, you need to change the code

Me.Close

to

Form1.Close

or whatever the name of your main form is.

Now once you have finished your build for your program and it is ready for release, just click the "Debug" menu item on Visual Basic and click Build YOUR PROGRAM NAME and go to your projects folder in My Documents > VB 2010/2008 > Projects > Your program > Your program > Bin > Release

Just copy and paste your program into your Dropbox folder and you are done!

Once you want to release an update to your program just replace the old version of your program in your Dropbox folder with your latest version and then open your version.txt file and change the text to the latest version like change it from 1.0.0.0 to 2.0.0.0.

Let's understand how this works. You replace the files and change the version text. Your users open the updater, it checks the version.txt tex and checks if your current version is greater than or equal to the latest version. If the latest version is greater than your current version, it will enable the button which will allow the user to download your program. The program will then let then download the newer program and will let the user know the progress of the download and close the old version, then open the new version and delete the old version. Viola! You now have an updater for your program!

You can use this information to do many more things to make it even better. I like to add a textbox that has information about the latest version and I add an autoupdater to my programs like xPro.

Source: [ Register or Signin to view external links. ]

I hope this tutorial helps you guys. I made another tutorial a while back but nobody wanted to watch a 24 minute video lol. This is also a better version as well. If you have any questions, feel free to ask!
#2. Posted:
Rhymes
  • TTG Addict
Status: Offline
Joined: Dec 30, 201112Year Member
Posts: 2,311
Reputation Power: 120
Status: Offline
Joined: Dec 30, 201112Year Member
Posts: 2,311
Reputation Power: 120
Nice to see new members contributing something. However, if I had no understanding of VB I wouldn't know what you were talking about. Luckily, anyone that has the smarts to make a program they plan on updating with a auto updater should understand what your saying. Anyway, nice job.
#3. Posted:
OmitZz
  • Junior Member
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 68
Reputation Power: 2
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 68
Reputation Power: 2
Rhymes wrote Nice to see new members contributing something. However, if I had no understanding of VB I wouldn't know what you were talking about. Luckily, anyone that has the smarts to make a program they plan on updating with a auto updater should understand what your saying. Anyway, nice job.


Thank you. I recently got an idea of how I can rework this and make it simpler. I may get to it someday lol. I do at least have the source code for people to use but this dang site and changing the dropbox linsk :\
#4. Posted:
Bashful
  • TTG Senior
Status: Offline
Joined: Aug 02, 201212Year Member
Posts: 1,915
Reputation Power: 77
Status: Offline
Joined: Aug 02, 201212Year Member
Posts: 1,915
Reputation Power: 77
OmitZz wrote
Rhymes wrote Nice to see new members contributing something. However, if I had no understanding of VB I wouldn't know what you were talking about. Luckily, anyone that has the smarts to make a program they plan on updating with a auto updater should understand what your saying. Anyway, nice job.


Thank you. I recently got an idea of how I can rework this and make it simpler. I may get to it someday lol. I do at least have the source code for people to use but this dang site and changing the dropbox linsk :\

An easier way to do this, is use a free hosting site. Your link would always be similar if you wanted.
#5. Posted:
OmitZz
  • Junior Member
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 68
Reputation Power: 2
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 68
Reputation Power: 2
Mimz wrote
OmitZz wrote
Rhymes wrote Nice to see new members contributing something. However, if I had no understanding of VB I wouldn't know what you were talking about. Luckily, anyone that has the smarts to make a program they plan on updating with a auto updater should understand what your saying. Anyway, nice job.


Thank you. I recently got an idea of how I can rework this and make it simpler. I may get to it someday lol. I do at least have the source code for people to use but this dang site and changing the dropbox linsk :\

An easier way to do this, is use a free hosting site. Your link would always be similar if you wanted.


The link stays the same on dropbox?
#6. Posted:
DimiPro
  • TTG Senior
Status: Offline
Joined: Oct 18, 201113Year Member
Posts: 1,200
Reputation Power: 48
Status: Offline
Joined: Oct 18, 201113Year Member
Posts: 1,200
Reputation Power: 48
thanks man maybe ill take a look into it later
#7. Posted:
Bashful
  • TTG Senior
Status: Offline
Joined: Aug 02, 201212Year Member
Posts: 1,915
Reputation Power: 77
Status: Offline
Joined: Aug 02, 201212Year Member
Posts: 1,915
Reputation Power: 77
OmitZz wrote
Mimz wrote
OmitZz wrote
Rhymes wrote Nice to see new members contributing something. However, if I had no understanding of VB I wouldn't know what you were talking about. Luckily, anyone that has the smarts to make a program they plan on updating with a auto updater should understand what your saying. Anyway, nice job.


Thank you. I recently got an idea of how I can rework this and make it simpler. I may get to it someday lol. I do at least have the source code for people to use but this dang site and changing the dropbox linsk :\

An easier way to do this, is use a free hosting site. Your link would always be similar if you wanted.


The link stays the same on dropbox?

I never really used dropbox. But I meant that you have the ability to customize links but keep it the same.
You could use an alias for [ Register or Signin to view external links. ]
It would put it to whatever you linked the alias to, etc.
#8. Posted:
OmitZz
  • Junior Member
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 68
Reputation Power: 2
Status: Offline
Joined: Jul 26, 201212Year Member
Posts: 68
Reputation Power: 2
Mimz wrote
OmitZz wrote
Mimz wrote
OmitZz wrote
Rhymes wrote Nice to see new members contributing something. However, if I had no understanding of VB I wouldn't know what you were talking about. Luckily, anyone that has the smarts to make a program they plan on updating with a auto updater should understand what your saying. Anyway, nice job.


Thank you. I recently got an idea of how I can rework this and make it simpler. I may get to it someday lol. I do at least have the source code for people to use but this dang site and changing the dropbox linsk :\

An easier way to do this, is use a free hosting site. Your link would always be similar if you wanted.


The link stays the same on dropbox?

I never really used dropbox. But I meant that you have the ability to customize links but keep it the same.
You could use an alias for [ Register or Signin to view external links. ]
It would put it to whatever you linked the alias to, etc.


I enjoy the convenience and simplicity of Dropbox. I understand what your saying though. Whatever way you want to make things work is cool.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.