我有一个用VB.Net编写的程序,这个程序应该自动更新.我已经找到了如何下载新文件并解压缩它,问题是我无法覆盖文件,只要它在执行中.这是怎么做到的?我想到了一个单独的exe上的“更新程序”但是会有同样的问题,当我做一些更改时我无法更新更新程序…
只需关闭旧程序即可.
原文链接:https://www.f2er.com/vb/255820.html保留单独的更新程序,然后当您想要更新旧程序时,让更新程序关闭旧程序,然后下载新版本的应用程序.例如,
更新程序,
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