0

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

4

5 回答 5

3

只需关闭旧程序。

保留单独的更新程序,然后当您要更新旧程序时,让更新程序关闭旧程序,然后下载您的应用程序的新版本。例如,

更新程序,

 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
于 2013-05-19T16:46:15.490 回答
2

老问题,但我所做的是,当我在我的主程序中时,我复制重命名当前更新程序,然后像这样调用重命名的更新程序:

(注意,为了解释和说明,代码已被简化)

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

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

于 2015-12-03T22:58:47.377 回答
1

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

于 2013-05-19T15:15:13.257 回答
0

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

sub MDImainEXE_load()
DLL.function like that
end sub

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

sub updateEXE_load()
DLL.function like that
end sub

如果困惑然后问什么困惑。

于 2013-05-19T15:33:17.477 回答
0

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

在这里看到

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

于 2013-05-19T16:29:39.380 回答