在线升级。高手帮帮忙
Public Sub UpData() '在线升级
On Error Resume Next
Dim MyData() As Byte, VerInfo() As Byte, Ti As Long, Tj As Long
If Inet1.StillExecuting = True Then Exit Sub
VerInfo() = Inet1.OpenURL("http://www.xxx.com/uploadsoft/update.txt", icString)
Ti = InStr(1, VerInfo, vbCrLf) + 2
Tj = InStr(Ti, VerInfo, vbCrLf)
'检测版本号
If Val(Left$(VerInfo, Ti - 3)) <= Val(App.Major & "." & App.Minor & App.Revision) Then Exit Sub
If MsgBox("SWpsF 发布了新的版本:" + Left$(VerInfo, Ti - 3) + ",文件大小:" + Mid$(VerInfo, Tj + 2) + ",是否进行在线升级 ?", vbYesNo + vbQuestion, "在线升级") = vbNo Then Exit Sub
IsUp = True
'开始下载更新文件
MyData() = Inet1.OpenURL("http://www.xxx.com/uploadsoft/" + Mid$(VerInfo, Ti, Tj - Ti), icByteArray)
Open App.Path + "\" + Mid$(VerInfo, Ti, Tj - Ti) For Binary Access Write As #1
Put #1, , MyData()
Close #1
IsUp = False
'执行更新文件
ShellExecute 0, vbNullString, App.Path + "\" + Mid$(VerInfo, Ti, Tj - Ti), vbNullString, App.Path, SW_SHOWNORMAL
End
End Sub
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
在执行了put #1,,mydata() 以后,写出的文件是一个4K大小的文件,文件名是一样的,不是我想要下来的文件,请高手帮看下有什么问题,还有啊,后面这个SHELLEXECUTE可以在本程序执行的时候强制关闭掉本身而运行那个程序吗?
[解决办法]
建议你直接将升级模块做成另一个EXE,主程序检测到了更新版后启动升级EXE,让它在后台下载.
下载完成后再通知用户,是否关闭主程序以进行更新.
这样的话编码难度小,结构也清晰了.