VB.Net程序应自动更新 [英] VB.Net Program should auto update

查看:662
本文介绍了VB.Net程序应自动更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用VB.Net编写的程序,该程序应该可以自动更新.我已经找到了如何下载新文件并将其解压缩,问题是只要执行该文件便无法覆盖该文件.这通常如何完成?我想到了一个单独的exe上的更新程序",但这会遇到相同的问题,当我进行一些更改时我无法更新该更新程序...

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

推荐答案

只需关闭旧程序.

保留单独的更新程序,然后在要更新旧程序时,使更新程序关闭旧程序,然后下载新版本的应用程序.例如,

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,

更新程序

 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

这篇关于VB.Net程序应自动更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆