打印本文 打印本文 关闭窗口 关闭窗口
用VB6.0编写自我升级的程序(三)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2042  更新时间:2009/4/23 15:03:53  文章录入:mintao  责任编辑:mintao

'''' ------------------------------------------

 

Dim State As Boolean

 

Private Sub Command1_Click()

  Unload Me

End Sub

 

Private Sub Form_Activate()

 

  Dim i As Integer

  Dim j As String

 

  Dim OldExeFile As String

  Dim NewExeFile As String

 

  Dim tmpFile As String

  Dim MainState As Boolean

 

 

  DoEvents

   

  If State Then

     '''' 获取旧主程序名称

     OldExeFile = CStr(ReadIniFile(UpdateIniPath, "Main", "Name", "主程序"))

     NewExeFile = OldExeFile

     OldExeFile = App.Path & "\" & OldExeFile & ".exe"

     tmpFile = App.Path & "\tmp.tmp"

    

     '''' 改写升级次数

     i = CInt(ReadIniFile(UpdateIniPath, "Update", "Num", "0"))

     i = i + 1

     ChangeLabelPos Me, lblCap, "这是您第" & i & "次升级!"

     Sleep 1500

    

     '''' 摸拟从网站下载新的更新程序。

     ChangeLabelPos Me, lblCap, "正在 摸拟从网站下载新的升级程序 ..."

     Sleep 1000

     On Error Resume Next

     Kill tmpFile

     '''' 此处可以修改为将临时文件放在临时文件夹内

     SaveFileFromRes 101, "CUSTOM", tmpFile

     Sleep 1000

     On Error GoTo 0

    

     '''' 检查主程序是否开启,若开启则关闭旧程序

     MainState = CBool(CInt(ReadIniFile(UpdateIniPath, "Main", "Active", "0")))

     If MainState Then

       '''' 关闭旧程序

       ChangeLabelPos Me, lblCap, "正在关闭旧程序 ... "

       Sleep 300

      

       '''' 这里强行关闭旧程序

       '''' 你也可以发送消息,让旧程序自己关闭

       Do While -1

          DoEvents

          If CloseValidForm(NewExeFile) Then

             Exit Do

          End If

       Loop

       Sleep 200

     End If

    

     '''' 删除旧程序

     On Error Resume Next

     ChangeLabelPos Me, lblCap, "正在删除旧程序 ... "

     Sleep 1000

     Kill OldExeFile

     Sleep 1000

    

    

     '''' 生成新主程序名称

''''     NewExeFile = CStr(ReadIniFile(UpdateIniPath, "Main", "Name", "主程序"))

     j = Right(NewExeFile, 1)

     If IsNumeric(j) Then

        j = i

        NewExeFile = Left(NewExeFile, Len(NewExeFile) - 1)

     Else

        j = 1

     End If

     '''' 记录主程序的名字

     NewExeFile = NewExeFile & j

     WritePrivateProfileString "Main", "Name", NewExeFile, UpdateIniPath

     NewExeFile = App.Path & "\" & NewExeFile & ".exe"

    

    

     '''' 拷贝新程序

     ChangeLabelPos Me, lblCap, "正在更新程序 ... "

     Sleep 1000

     FileCopy tmpFile, NewExeFile

     Sleep 1000

     '''' 删除临时程序

     Kill tmpFile

    

上一页  [1] [2] [3]  下一页

打印本文 打印本文 关闭窗口 关闭窗口