VB怎么实现更新程序 20
功能:检测某网页txt或html中版本是否与当前版本一致,若不一致则打开txt或html中指定的地址下载更新文件打开下载的更新文件...
功能:
检测某网页txt或html中版本是否与当前版本一致,若不一致则打开txt或html中指定的地址下载更新文件
打开下载的更新文件 展开
检测某网页txt或html中版本是否与当前版本一致,若不一致则打开txt或html中指定的地址下载更新文件
打开下载的更新文件 展开
1个回答
展开全部
wstr = Inet1.OpenURL("http://www.xxx.com/1.txt")
If wstr <> "" And wstr <> "v1.0" Then
a = MsgBox("你好,检查到远程有升级程序,是否更新?", vbOKCancel, "提示")
If a = 1 Then '确定更新
DownFile
End If
ElseIf wstr = "" Or wstr = "v1.0" Then
MsgBox "当前此版本为最新程序,若有建议请联系QQ:121734199", vbOKOnly, "提示"
End If
Private Sub DownFile()
If ii = 0 Then
strURL = "http://www.xxx.com/xiaoshuo/小说.exe"
mstrFileName = App.Path & "\小说_v1.0.exe"
ElseIf ii = 1 Then
strURL = "http://www.xxx.com/xiaoshuo/更名器.exe"
mstrFileName = App.Path & "\更名器.exe"
Else
Shell App.Path & "\更名器.exe", vbHide
End
End If
mblnPutStart = False
With Winsock1
If .State <> sckClosed Then .Close
.Protocol = sckTCPProtocol
.RemoteHost = Split(Replace(strURL, "http://", ""), "/")(0)
.RemotePort = 80
.Connect
End With
End Sub
Private Sub Winsock1_Connect()
Dim s As String
s = "GET " + strURL + " HTTP/1.0" + vbCrLf
s = s + "Accept: */*" + vbCrLf
s = s & "Pragma: no-cache" & vbCrLf
s = s & "Cache-Control: no-cache" & vbCrLf
s = s & "Connection: close" & vbCrLf & vbCrLf
s = s + vbCrLf
Winsock1.SendData s
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim RevData() As Byte
Dim a() As Byte, b() As String, c() As String
Dim s As String, i As Long, k As Long
On Error GoTo fail
If mblnPutStart = False Then
Winsock1.PeekData RevData, vbArray Or vbByte
k = InStrB(1, RevData, ChrB(13) & ChrB(10) & ChrB(13) & ChrB(10))
If k > 0 Then
Winsock1.GetData RevData, vbArray Or vbByte
a = LeftB(RevData, k - 1)
RevData = MidB(RevData, k + 4)
s = StrConv(a, vbUnicode)
b = Split(s, vbCrLf)
If InStr(1, b(0), "200 OK", vbTextCompare) = 0 Then GoTo fail
For i = 1 To UBound(b)
c = Split(b(i), ": ")
Select Case c(0)
Case "Content-Length"
mlngFileLen = CLng(c(1))
End Select
Next
mblnPutStart = True
mlngCurByte = UBound(RevData) + 1
mlngFileNum = FreeFile
Open mstrFileName For Binary As #mlngFileNum
Else
Exit Sub
End If
Else
Winsock1.GetData RevData, vbArray Or vbByte
mlngCurByte = mlngCurByte + bytesTotal
End If
Put #mlngFileNum, , RevData
Label3.Caption = "已下载字节:" & mlngCurByte & "/" & mlngFileLen
If mlngCurByte = mlngFileLen Then
Close #mlngFileNum
ii = ii + 1
DownFile
End If
Exit Sub
fail:
MsgBox "网络传输错误,文件下载失败!"
End Sub
If wstr <> "" And wstr <> "v1.0" Then
a = MsgBox("你好,检查到远程有升级程序,是否更新?", vbOKCancel, "提示")
If a = 1 Then '确定更新
DownFile
End If
ElseIf wstr = "" Or wstr = "v1.0" Then
MsgBox "当前此版本为最新程序,若有建议请联系QQ:121734199", vbOKOnly, "提示"
End If
Private Sub DownFile()
If ii = 0 Then
strURL = "http://www.xxx.com/xiaoshuo/小说.exe"
mstrFileName = App.Path & "\小说_v1.0.exe"
ElseIf ii = 1 Then
strURL = "http://www.xxx.com/xiaoshuo/更名器.exe"
mstrFileName = App.Path & "\更名器.exe"
Else
Shell App.Path & "\更名器.exe", vbHide
End
End If
mblnPutStart = False
With Winsock1
If .State <> sckClosed Then .Close
.Protocol = sckTCPProtocol
.RemoteHost = Split(Replace(strURL, "http://", ""), "/")(0)
.RemotePort = 80
.Connect
End With
End Sub
Private Sub Winsock1_Connect()
Dim s As String
s = "GET " + strURL + " HTTP/1.0" + vbCrLf
s = s + "Accept: */*" + vbCrLf
s = s & "Pragma: no-cache" & vbCrLf
s = s & "Cache-Control: no-cache" & vbCrLf
s = s & "Connection: close" & vbCrLf & vbCrLf
s = s + vbCrLf
Winsock1.SendData s
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim RevData() As Byte
Dim a() As Byte, b() As String, c() As String
Dim s As String, i As Long, k As Long
On Error GoTo fail
If mblnPutStart = False Then
Winsock1.PeekData RevData, vbArray Or vbByte
k = InStrB(1, RevData, ChrB(13) & ChrB(10) & ChrB(13) & ChrB(10))
If k > 0 Then
Winsock1.GetData RevData, vbArray Or vbByte
a = LeftB(RevData, k - 1)
RevData = MidB(RevData, k + 4)
s = StrConv(a, vbUnicode)
b = Split(s, vbCrLf)
If InStr(1, b(0), "200 OK", vbTextCompare) = 0 Then GoTo fail
For i = 1 To UBound(b)
c = Split(b(i), ": ")
Select Case c(0)
Case "Content-Length"
mlngFileLen = CLng(c(1))
End Select
Next
mblnPutStart = True
mlngCurByte = UBound(RevData) + 1
mlngFileNum = FreeFile
Open mstrFileName For Binary As #mlngFileNum
Else
Exit Sub
End If
Else
Winsock1.GetData RevData, vbArray Or vbByte
mlngCurByte = mlngCurByte + bytesTotal
End If
Put #mlngFileNum, , RevData
Label3.Caption = "已下载字节:" & mlngCurByte & "/" & mlngFileLen
If mlngCurByte = mlngFileLen Then
Close #mlngFileNum
ii = ii + 1
DownFile
End If
Exit Sub
fail:
MsgBox "网络传输错误,文件下载失败!"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
微测检测5.10
2023-05-10 广告
2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询