VB.Net 程序应该自动更新

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16636096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 13:38:46  来源:igfitidea点击:

VB.Net Program should auto update

vb.netauto-update

提问by sharkyenergy

I have a program written in VB.Netand 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...

我写了一个程序VB.Net,这个程序应该自动更新。我已经找到了如何下载新文件并解压缩它,问题是只要它正在执行,我就无法覆盖该文件。这是如何正常完成的?我想过一个单独的 exe 上的“更新程序”,但这会有同样的问题,当我进行一些更改时我无法更新更新程序......

回答by Sam

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

回答by Sam

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.

然后,当您的更新程序完成它的工作时,它将更新 MyUpdater.exe 以及其他所有内容。

回答by Douglas Barbin

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

为什么不创建一个 ClickOnce 部署,并将它托管在某个地方?

回答by Vin

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

简单的解决方案,只需将 exe 文件源代码分成多个 DLL 文件(如按模块划分),并让主 exe 执行 dll 代码,如

sub MDImainEXE_load()
DLL.function 就像
end sub一样,

您可以使用相同的更新 exe 的方法发送带有配置和 DLL 的新主 exe,配置文件将包含要更新的 DLL 名称,如果更新 exe 必须更新,则将该 DLL 命名为要使用的参数,因为更新 exe 不包含代码,只需使用 DLL 文件名中的函数从配置文件参数。

sub updateEXE_load()
DLL.function 就像那个
end sub

if confused then ask what confused.

如果困惑,那么问什么困惑。

回答by matzone

Maybe something like Create A Dump File for a Running Process

也许类似于为正在运行的进程创建转储文件

You see it here

在这里看到

But it depends on your VB version....

但这取决于您的VB版本....