开发环境VB6
用文件替换来实现程式版本更新.
将exe文件放入数据库资料表, 保存为image类型数据.
客户端连接数据库将内容下载到本地.
exe文件名为"TEST".
Dir(strFile) '查找文件
Kill strFile '删除文件
Shell(appPath & "\TEST.exe", vbNormalFocus) '执行文件
使用ADO GetChunk/AppendChunk 数据库存取二进制文件
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
FindWindow(vbNullString, "TEST") '按名字查找窗口, 用来判断TEST.exe是否正在执行.
Open strFile For Binary As #1 '创建2进制文件
Put #1, , ByteX '将ByteX写入文件
将exe文件存入数据库资料表
Open strFileName For Binary As #intFile '打开文件
lngCount = LOF(intFile)
ReDim bData(lngCount) As Byte
Get #intFile, , bData '将文件放入2进制变量
Close #intFile
Dim adoRs As New ADODB.Recordset
If DbConnection = True Then '开启数据连接 , 代码省略
With adoRs
.Open " Select projectname,projectdesc,projectexe,filecreatedate," _
& " usermoddate,moduserip From projectversion " _
& " Where projectname='" & strFileShortName & "' and filecreatedate>='" _
& Format(FileDateTime(strFileName), "yyyy-MM-dd hh:MM:ss") & "' " _
, Cn, adOpenDynamic, adLockOptimistic
If .EOF Then
.AddNew
End If
.Fields("projectname") = strFileShortName
.Fields("projectdesc") = "TEST"
.Fields("projectexe").AppendChunk bData()
.Fields("moduserip") = Trim(Me.Winsock1.LocalIP)
.Fields("filecreatedate") = Format(FileDateTime(strFileName), "yyyy-MM-dd hh:MM:ss")
.Fields("usermoddate") = Format(Now, "yyyy-MM-dd hh:MM:ss")
.Update
End With
End If
客户端连接数据库下载exe文件,替换本地文件.
Dim ByteX() As Byte
Dim AdoFile As New ADODB.Recordset
Dim strFile As String
strFile = "appPath\TEST.exe" 'exe文件存放路径
AdoFile.Open "select projectname,projectexe,filecreatedate " _
& " from projectversion where projectname = 'TEST' order by filecreatedate desc", Cn, adOpenDynamic, adLockOptimistic
If Not AdoFile.EOF Then
AdoFile.MoveFirst
If AdoFile.Fields("projectexe").ActualSize > 0 Then
ByteX = AdoFile.Fields("projectexe").GetChunk(AdoFile.Fields("projectexe").ActualSize)
If Dir(strFile) <> "" Then Kill strFile 'exe文件已存在,则删除.
Open strFile For Binary As #1 '创建2进制文件
Put #1, , ByteX '将ByteX写入
Close #1
End If
End If