VB.NET实现应用程序自动更新1

VB.NET实现应用程序自动更新1
2008/08/02 12:51

Imports System
Imports System.Net
Imports System.Text
Imports System.Threading
Imports Scripting
Imports System.io
Imports Fairy4_Api
Imports DevExpress.XtraEditors
Friend Class update
    Inherits System.Windows.Forms.Form

    Private MyWebClient As New WebClient
    Private ByteNum As Long
    ' Private Threaddown, Threadchk As Thread
    Private Mybyte() As Byte
    Private Zipsize As Long
    Private Func As New Func
    Private fso As New FileSystemObject
    Private fl As Scripting.File
    Private Ready As String = Application.StartupPath & "/images/ready.ico"
    Private down As String = Application.StartupPath & "/images/down.ico"
    Private Err As String = Application.StartupPath & "/images/Error.ico"
    Private Inipath As String = Application.StartupPath & "/update.ini"
    Private Tempfolder As String = Application.StartupPath & "/temp_download" '临时下载文件夹
    Private Address As String '下载网站
    Private SleepTime As Integer '下載完一個進程休眠時間:單位毫秒
    Private RunProgrom As String
    Private KillProgrom As String

    Public UpdateDataSet As New DataSet '升级配置文件数据集
    Private Curversion As String
    Private Alldownloadbyte As Long = 0
    Private Runthread As Thread '执行时候运行的线程
    Private Myapi As New Fairy4_Api.My_Api
    '############################
    '程式製作:Fairy4
    '參考網友:雨浪 部分源碼
    'Mail_To: Phoenix4197@163.com
    '############################

#Region " Windows 窗体设计器生成的代码 "

    Public Sub New()
        MyBase.New()

        '该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        '在 InitializeComponent() 调用之后添加任何初始化

    End Sub

    '窗体重写 dispose 以清理组件列表。
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Windows 窗体设计器所必需的
    Private components As System.ComponentModel.IContainer

    '注意: 以下过程是 Windows 窗体设计器所必需的
    '可以使用 Windows 窗体设计器修改此过程。
    '不要使用代码编辑器修改它。
    Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents PictureBox2 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox3 As System.Windows.Forms.PictureBox
    Friend WithEvents Label5 As System.Windows.Forms.Label
    Friend WithEvents Label6 As System.Windows.Forms.Label
    Friend WithEvents lbl As System.Windows.Forms.Label
    Friend WithEvents btnupdate As System.Windows.Forms.Button
    Friend WithEvents btnclose As System.Windows.Forms.Button
    Friend WithEvents Label8 As System.Windows.Forms.Label
    Friend WithEvents Label9 As System.Windows.Forms.Label
    Friend WithEvents Label10 As System.Windows.Forms.Label
    Friend WithEvents PictureBox4 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox9 As System.Windows.Forms.PictureBox
    ' Friend WithEvents Progressdownload As DevExpress.XtraEditors.ProgressBarControl ' DevExpress.XtraEditors.ProgressBarControl
    Friend WithEvents Label4 As System.Windows.Forms.Label
    'Friend WithEvents ProgressCdownload As DevExpress.XtraEditors.ProgressBarControl
    Friend WithEvents Label7 As System.Windows.Forms.Label
    Friend WithEvents PictureBox5 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox6 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox7 As System.Windows.Forms.PictureBox
    Friend WithEvents PictureBox8 As System.Windows.Forms.PictureBox
    Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents Progressdownload As DevExpress.XtraEditors.ProgressBarControl
    Friend WithEvents ProgressCdownload As DevExpress.XtraEditors.ProgressBarControl
    Friend WithEvents AxWebBrowser1 As AxSHDocVw.AxWebBrowser
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(update))
        Me.PictureBox1 = New System.Windows.Forms.PictureBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
        Me.Label2 = New System.Windows.Forms.Label
        Me.GroupBox1 = New System.Windows.Forms.GroupBox
        Me.ProgressCdownload = New DevExpress.XtraEditors.ProgressBarControl
        Me.Progressdownload = New DevExpress.XtraEditors.ProgressBarControl
        Me.Label4 = New System.Windows.Forms.Label
        Me.Label5 = New System.Windows.Forms.Label
        Me.PictureBox2 = New System.Windows.Forms.PictureBox
        Me.PictureBox3 = New System.Windows.Forms.PictureBox
        Me.PictureBox4 = New System.Windows.Forms.PictureBox
        Me.Label6 = New System.Windows.Forms.Label
        Me.btnupdate = New System.Windows.Forms.Button
        Me.lbl = New System.Windows.Forms.Label
        Me.btnclose = New System.Windows.Forms.Button
        Me.PictureBox5 = New System.Windows.Forms.PictureBox
        Me.Label8 = New System.Windows.Forms.Label
        Me.PictureBox6 = New System.Windows.Forms.PictureBox
        Me.Label9 = New System.Windows.Forms.Label
        Me.PictureBox7 = New System.Windows.Forms.PictureBox
        Me.Label10 = New System.Windows.Forms.Label
        Me.PictureBox9 = New System.Windows.Forms.PictureBox
        Me.PictureBox8 = New System.Windows.Forms.PictureBox
        Me.Label7 = New System.Windows.Forms.Label
        Me.Label3 = New System.Windows.Forms.Label
        Me.AxWebBrowser1 = New AxSHDocVw.AxWebBrowser
        Me.GroupBox2 = New System.Windows.Forms.GroupBox
        Me.GroupBox1.SuspendLayout()
        CType(Me.ProgressCdownload.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.Progressdownload.Properties, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.AxWebBrowser1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.GroupBox2.SuspendLayout()
        Me.SuspendLayout()
        '
        'PictureBox1
        '
        Me.PictureBox1.Location = New System.Drawing.Point(20, 83)
        Me.PictureBox1.Name = "PictureBox1"
        Me.PictureBox1.Size = New System.Drawing.Size(20, 20)
        Me.PictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.PictureBox1.TabIndex = 0
        Me.PictureBox1.TabStop = False
        '
        'Label1
        '
        Me.Label1.ImageList = Me.ImageList1
        Me.Label1.Location = New System.Drawing.Point(60, 86)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(123, 17)
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "正在连接到服务器..."
        '
        'ImageList1
        '
        Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
        Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(60, 120)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(123, 17)
        Me.Label2.TabIndex = 3
        Me.Label2.Text = "正在检查更新版本..."
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.ProgressCdownload)
        Me.GroupBox1.Controls.Add(Me.Progressdownload)
        Me.GroupBox1.Controls.Add(Me.Label4)
        Me.GroupBox1.Controls.Add(Me.Label5)
        Me.GroupBox1.Location = New System.Drawing.Point(15, 231)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(369, 112)
        Me.GroupBox1.TabIndex = 14
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "下载进度"
        '
        'ProgressCdownload
        '
        Me.ProgressCdownload.Location = New System.Drawing.Point(80, 40)
        Me.ProgressCdownload.Name = "ProgressCdownload"
        Me.ProgressCdownload.Size = New System.Drawing.Size(264, 14)
        Me.ProgressCdownload.TabIndex = 7
        Me.ProgressCdownload.TabStop = False
        '
        'Progressdownload
        '
        Me.Progressdownload.Location = New System.Drawing.Point(80, 72)
        Me.Progressdownload.Name = "Progressdownload"
        Me.Progressdownload.Size = New System.Drawing.Size(264, 14)
        Me.Progressdownload.TabIndex = 6
        Me.Progressdownload.TabStop = False
        '
        'Label4
        '
        Me.Label4.Location = New System.Drawing.Point(13, 40)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(54, 17)
        Me.Label4.TabIndex = 5
        Me.Label4.Text = "当前进度"
        '
        'Label5
        '
        Me.Label5.Location = New System.Drawing.Point(13, 74)
        Me.Label5.Name = "Label5"
        Me.Label5.Size = New System.Drawing.Size(54, 17)
        Me.Label5.TabIndex = 1
        Me.Label5.Text = "总体进度"
        '
        'PictureBox2
        '
        Me.PictureBox2.Location = New System.Drawing.Point(20, 117)
        Me.PictureBox2.Name = "PictureBox2"
        Me.PictureBox2.Size = New System.Drawing.Size(20, 20)
        Me.PictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.PictureBox2.TabIndex = 15
        Me.PictureBox2.TabStop = False
        '
        'PictureBox3
        '
        Me.PictureBox3.Location = New System.Drawing.Point(20, 152)
        Me.PictureBox3.Name = "PictureBox3"
        Me.PictureBox3.Size = New System.Drawing.Size(20, 20)
        Me.PictureBox3.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.PictureBox3.TabIndex = 16
        Me.PictureBox3.TabStop = False
        '
        'PictureBox4
        '
        Me.PictureBox4.Location = New System.Drawing.Point(20, 186)
        Me.PictureBox4.Name = "PictureBox4"
        Me.PictureBox4.Size = New System.Drawing.Size(20, 20)
        Me.PictureBox4.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.PictureBox4.TabIndex = 18
        Me.PictureBox4.TabStop = False
        '
        'Label6
        '
        Me.Label6.Location = New System.Drawing.Point(60, 189)
        Me.Label6.Name = "Label6"
        Me.Label6.Size = New System.Drawing.Size(123, 17)
        Me.Label6.TabIndex = 17
        Me.Label6.Text = "正在下载更新版本..."
        '
        'btnupdate
        '
        Me.btnupdate.Image = CType(resources.GetObject("btnupdate.Image"), System.Drawing.Image)
        Me.btnupdate.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.btnupdate.Location = New System.Drawing.Point(223, 360)
        Me.btnupdate.Name = "btnupdate"
        Me.btnupdate.Size = New System.Drawing.Size(81, 26)
        Me.btnupdate.TabIndex = 19
        Me.btnupdate.Text = "开始升级"
        Me.btnupdate.TextAlign = System.Drawing.ContentAlignment.BottomRight
        '
        'lbl
        '
        Me.lbl.ForeColor = System.Drawing.Color.Red
        Me.lbl.Location = New System.Drawing.Point(21, 361)
        Me.lbl.Name = "lbl"
        Me.lbl.Size = New System.Drawing.Size(181, 17)
        Me.lbl.TabIndex = 20
        '
        'btnclose
        '
        Me.btnclose.Image = CType(resources.GetObject("btnclose.Image"), System.Drawing.Image)
        Me.btnclose.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft
        Me.btnclose.Location = New System.Drawing.Point(320, 360)
        Me.btnclose.Name = "btnclose"
        Me.btnclose.Size = New System.Drawing.Size(56, 26)
        Me.btnclose.TabIndex = 21
        Me.btnclose.Text = "关闭"
        Me.btnclose.TextAlign = System.Drawing.ContentAlignment.BottomRight
        '
        'PictureBox5
        '
        Me.PictureBox5.Location = New System.Drawing.Point(197, 83)
        Me.PictureBox5.Name = "PictureBox5"
        Me.PictureBox5.Size = New System.Drawing.Size(20, 20)
        Me.PictureBox5.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.PictureBox5.TabIndex = 25
        Me.PictureBox5.TabStop = False
        '
        'Label8
        '
        Me.Label8.Location = New System.Drawing.Point(237, 86)
        Me.Label8.Name = "Label8"
        Me.Label8.Size = New System.Drawing.Size(140, 17)
        Me.Label8.TabIndex = 24
        Me.Label8.Text = "正在关闭应用程序..."
        '
        'PictureBox6
        '
        Me.PictureBox6.Location = New System.Drawing.Point(197, 117)
        Me.PictureBox6.Name = "PictureBox6"
        Me.PictureBox6.Size = New System.Drawing.Size(20, 20)
        Me.PictureBox6.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.PictureBox6.TabIndex = 27
        Me.PictureBox6.TabStop = False
        '
        'Label9
        '
        Me.Label9.Location = New System.Drawing.Point(237, 120)
        Me.Label9.Name = "Label9"
        Me.Label9.Size = New System.Drawing.Size(140, 17)
        Me.Label9.TabIndex = 26
        Me.Label9.Text = "正在执行更新过程..."
        '
        'PictureBox7
        '
        Me.PictureBox7.Location = New System.Drawing.Point(197, 152)
        Me.PictureBox7.Name = "PictureBox7"
        Me.PictureBox7.Size = New System.Drawing.Size(20, 20)
        Me.PictureBox7.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.PictureBox7.TabIndex = 29
        Me.PictureBox7.TabStop = False
        '
        'Label10
        '
        Me.Label10.Location = New System.Drawing.Point(237, 154)
        Me.Label10.Name = "Label10"
        Me.Label10.Size = New System.Drawing.Size(140, 17)
        Me.Label10.TabIndex = 28
        Me.Label10.Text = "更新完成,删除临时文件"
        '
        'PictureBox9
        '
        Me.PictureBox9.BackColor = System.Drawing.SystemColors.HighlightText
        Me.PictureBox9.Image = CType(resources.GetObject("PictureBox9.Image"), System.Drawing.Image)
        Me.PictureBox9.Location = New System.Drawing.Point(0, 0)
        Me.PictureBox9.Name = "PictureBox9"
        Me.PictureBox9.Size = New System.Drawing.Size(394, 56)
        Me.PictureBox9.TabIndex = 30
        Me.PictureBox9.TabStop = False
        Me.PictureBox9.Visible = False
        '
        'PictureBox8
        '
        Me.PictureBox8.Location = New System.Drawing.Point(197, 186)
        Me.PictureBox8.Name = "PictureBox8"
        Me.PictureBox8.Size = New System.Drawing.Size(20, 20)
        Me.PictureBox8.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage
        Me.PictureBox8.TabIndex = 32
        Me.PictureBox8.TabStop = False
        '
        'Label7
        '
        Me.Label7.Location = New System.Drawing.Point(237, 189)
        Me.Label7.Name = "Label7"
        Me.Label7.Size = New System.Drawing.Size(140, 17)
        Me.Label7.TabIndex = 31
        Me.Label7.Text = "更新成功,开启应用程序"
        '
        'Label3
        '
        Me.Label3.Location = New System.Drawing.Point(60, 154)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(123, 17)
        Me.Label3.TabIndex = 5
        Me.Label3.Text = "正在收集本机信息..."
        '
        'AxWebBrowser1
        '
        Me.AxWebBrowser1.ContainingControl = Me
        Me.AxWebBrowser1.Enabled = True
        Me.AxWebBrowser1.Location = New System.Drawing.Point(9, 11)
        Me.AxWebBrowser1.OcxState = CType(resources.GetObject("AxWebBrowser1.OcxState"), System.Windows.Forms.AxHost.State)
        Me.AxWebBrowser1.Size = New System.Drawing.Size(376, 60)
        Me.AxWebBrowser1.TabIndex = 33
        '
        'GroupBox2
        '
        Me.GroupBox2.BackColor = System.Drawing.Color.AliceBlue
        Me.GroupBox2.Controls.Add(Me.AxWebBrowser1)
        Me.GroupBox2.Location = New System.Drawing.Point(0, -4)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(394, 75)
        Me.GroupBox2.TabIndex = 34
        Me.GroupBox2.TabStop = False
        '
        'update
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 15)
        Me.ClientSize = New System.Drawing.Size(394, 399)
        Me.Controls.Add(Me.GroupBox2)
        Me.Controls.Add(Me.PictureBox8)
        Me.Controls.Add(Me.Label7)
        Me.Controls.Add(Me.PictureBox9)
        Me.Controls.Add(Me.PictureBox7)
        Me.Controls.Add(Me.Label10)
        Me.Controls.Add(Me.PictureBox6)
        Me.Controls.Add(Me.Label9)
        Me.Controls.Add(Me.PictureBox5)
        Me.Controls.Add(Me.Label8)
        Me.Controls.Add(Me.btnclose)
        Me.Controls.Add(Me.lbl)
        Me.Controls.Add(Me.btnupdate)
        Me.Controls.Add(Me.PictureBox4)
        Me.Controls.Add(Me.Label6)
        Me.Controls.Add(Me.PictureBox3)
        Me.Controls.Add(Me.PictureBox2)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.Label3)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.PictureBox1)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
        Me.Name = "update"
        Me.ShowInTaskbar = False
        Me.Text = "UUT在线升级程序"
        Me.GroupBox1.ResumeLayout(False)
        CType(Me.ProgressCdownload.Properties, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.Progressdownload.Properties, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.AxWebBrowser1, System.ComponentModel.ISupportInitialize).EndInit()
        Me.GroupBox2.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
VB.NET自动更新程序可以帮助我们在软件发布之后,通过自动下载和安装更新来保持软件的最新版本和功能。以下是一个简单的VB.NET自动更新程序的实现步骤: 1. 获取当前软件的版本号:使用VB.NET中的特定函数或方法,我们可以获取当前软件的版本号。 2. 检测更新:连接到服务器,检测是否有可用更新。可以通过访问一个特定的URL或从服务器获取一个更新文件来检查是否有新版本可用。 3. 下载更新:如果有可用的更新,使用VB.NET中的下载功能,从服务器上下载更新文件。 4. 检查下载文件的完整性和校验:使用哈希算法(如MD5或SHA)来检查下载的文件的完整性和校验。比较下载文件的哈希值与服务器上的哈希值是否匹配,以确保文件没有被更改或损坏。 5. 安装更新:解压下载的更新文件,并将更新文件应用到软件的相应位置。这可以通过调用外部可执行文件或通过VB.NET编写的代码实现。 6. 重启应用程序:在更新完成后,可能需要重新启动应用程序以使更新生效。 7. 定期检查更新:可以在应用程序启动时或定期检查更新,以确保用户一直使用最新版本的软件。 需要注意的是,VB.NET自动更新程序需要与服务器端进行交互,并且需要在发布新版本时更新服务器上的更新文件。此外,程序应该具有异常处理机制,以处理网络连接失败、下载文件损坏等情况。最后,还需要考虑用户隐私和安全性,确保更新过程中不会泄露敏感信息或遭受恶意软件攻击。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值