Ⅰ 怎樣用VB自動更新應用程序
s=trim(command())
'取得命令行參數
應該是這個形式:FastCopy.exe
網路目錄名,文件名
's的返回值是
網路目錄名,文件名
如:「\\liang\,myadd.exe"
'然後為了區分開目錄名和文件名,就查找","號
p=instr(1,s,",")
'如果找到就分別取「,」前面的目錄和後面的應用程序名。
Ⅱ VB怎麼實現更新程序
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
Ⅲ 怎樣用VB自動更新應用程序
s=trim(command())
'取得命令行參數 應該是這個形式:FastCopy.exe 網路目錄名,文件名
's的返回值是 網路目錄名,文件名 如:「\\liang\,myadd.exe"
'然後為了區分開目錄名和文件名,就查找","號
p=instr(1,s,",")
'如果找到就分別取「,」前面的目錄和後面的應用程序名。