VB.Net Program should auto update

2019-01-25 01:05发布

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...

5条回答
Deceive 欺骗
2楼-- · 2019-01-25 01:41

Why not just create a ClickOnce deployment, and host it somewhere?

查看更多
forever°为你锁心
3楼-- · 2019-01-25 01:44

simple solution, just divide the exe file source code into multiple DLL file(like divide in terms of modules) and have the main exe to execute the dll code like

sub MDImainEXE_load()
DLL.function like that
end sub

and you can use the same method for update exe send new main exe with configuration and DLL,configuration file will contain DLL names to update,if update exe has to update then name that DLL as argument to use because update exe will not contain code just use function from DLL file name from configuration file arguments.

sub updateEXE_load()
DLL.function like that
end sub

if confused then ask what confused.

查看更多
SAY GOODBYE
4楼-- · 2019-01-25 01:46

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
查看更多
仙女界的扛把子
5楼-- · 2019-01-25 01:49

Maybe something like Create A Dump File for a Running Process

You see it here

But it depends on your VB version....

查看更多
ゆ 、 Hurt°
6楼-- · 2019-01-25 01:49

Old question, but what I do is, when I am within my main program, I copy rename the current updater, and then call out to the renamed updater like so:

(note, code has been simplified for explanation and illustration)

FileCopy("MyUpdater.exe", "~MyUpdater.exe") ' rename the updater
Shell("~MyUpdater.exe") ' start the updater
END ' close the current program

Then when your updater does it's job, it will update MyUpdater.exe as well as everything else.

查看更多
登录 后发表回答