VB.Net Program should auto update

后端 未结 5 1470
忘了有多久
忘了有多久 2020-12-17 08:08

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 o

5条回答
  •  伪装坚强ぢ
    2020-12-17 08:49

    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
    

提交回复
热议问题