vb.netauto-update

VB.Net Program should auto update


I have a program written in VB.Net and this program is supposed to auto update. I already found how to download the new file and unzip it, problem is I cannot overwrite the file as long its in execution. How is this done normally? I thought about an "updater" on a separate exe but that would have the same problem, I couldn't update the updater when I make some changes...


Solution

  • Simply close the old program.

    Keep the separate updater program, then when you want to update your old program, get the updater to close the old program, then download the new version of your app. For example,

    Updater program,

     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        Do While True
            Dim client As New Net.WebClient
            Dim newVersion As String = client.DownloadString("http://www.myWebsite.com/updates/latestVersion.txt")
            If newVersion <> IO.File.ReadAllText("Your programs file location") Then
                For Each p As Process In Process.GetProcesses
                    If p.ProcessName = "your program's process name" Then 'If you don't know what your program's process name is, simply run your program, run windows task manager, select 'processes' tab, scroll down untill you find your programs name.
                        p.Kill()
                    End If
                Next
                IO.File.Delete("old program file location")
                client.DownloadFile("http://www.myWebsite.com/updates/12.05.2013.exe", "where ever you want to download your new program to (file location)")
                client.Dispose()
            End If
            Threading.Thread.Sleep(300000) 'freeze thread for 5 mins...
        Loop
    End Sub