用VB6.0编写自我升级的程序(三) (2)
中华网科技 http://tech.china.com
2005-06-23 11:47:25
|
|
|
Attribute VB_Name = "frmUpdate"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
‘ ------------------------------------------
‘ 升级程序的例子
‘ 作者: 谢家峰
‘ 日期: 2003/12/19 ‘
‘ 这里是升级程序
‘
‘ ------------------------------------------
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
首页 上页 | 1 | 2 | 3 | 4 | 下页 尾页 共 4 页 |