局域网环境下的软件在线自动升级
摘要:在有的电信运营企业,大多数赠品管理使用原始的手工账本登记方式,这种方式有多种弊端。开发一套赠品管理系统,以替代落后的手工记账方式,对提升单位的管理水平有着重要的意义。电信运营企业自身内部网络比较健全,根据现有的网络结构——内部局域网,开发终端应用程序即可,无须重新架设网络。一般只需开发一套C/S结构管理系统,使用一台计算机作为数据库服务器,终端程序安装在营业厅等营业终端电脑上,营业员及时把赠品使用情况录入到系统,就可以达到数据共享,从而实现及时掌握赠品动态信息、方便管理、提升管理效率的目的。
关键词:VB6.0;SQL Server2000数据库;自动升级
中图分类号:TN911文献标识码:A文章编号:1007-9599 (2010) 06-0000-02
Automatically Upgrade the Software Online under LAN
---- Based on VB6+ SQL Server2000 Realization
Xiao Shouxian
(Sanming Branch of CRC,Sanming365000,China)
Abstract:In telecom operators,most of the gifts management and use the original registration form by hand over the books,this approach has many drawbacks.Development of a gift management system to replace outdated manual accounting methods,to enhance the management level units of great significance.Their own internal network telecom operators relatively sound,according to the existing network structure - internal LAN,the terminal application can be developed without re-erected the network.Generally only develop a C/S structure,management system,using a computer as a database server,the terminal installed in the operating room and other business computer terminal,the sales staff in a timely manner to the use of gift entry to the system,you can achieve data sharing, thus dynamic information to grasp the realization of gifts,easy management,improve management efficiency.
Keywords:VB6.0;SQL Server2000 database;Automatic updates
在实际工作中,单位的赠品管理使用原始的手工账本登记方式,这种方式有多种弊端:不易查询、检索;不易统计、分析;不易管理者检查;不易掌握赠品动态信息等。开发一套赠品管理系统,以替代落后的管理手段,对全面提升赠品管理水平有着重要的意义。
本文主要介绍在VB6+SQL Server2000局域网环境下,实现软件在线自动升级的原理、步骤,及程序主要代码,以求抛砖引玉,不足之处,请大家指正。
一、软件在线自动升级原理概述
(一)查找远程上的更新
基于公司内部局域网网络结构,本软件采用Client/Server结构。Server端主要安装SQL Server2000数据库服务器,该服务器兼作软件升级FTP服务器。
程序运行时,首先与数据库服务器取得通信,从数据库表中获取最新版本信息。与既有版本信息进行比较,如果发现有新版本程序,就提示用户程序需要升级,并开始下载新版本程序。
数据库应用程序属于一种非常典型的前后台软件结构,前后台之间进行通信的主要机制称为数据库引擎,在VB中常用的数据库引擎有三种,即jet引擎,ODBC,OLE DB。
将上述三种数据库引擎封装成三种访问数据库的对象,即数据访问对象DAO、远程数据对象RDO和ActiveX数据对象ADO。本实例采用ADO对象与数据库进行通信。主要代码如下:
Public adocn As Connection
Public Sub Main()
Dim strsqlserver As String
Strsqlserver = "provider=sqloledb;server=10.88.64.119;user id=zpgl;password=;database=赠品管理"
If adocn Is Nothing Then
Set adocn = New Connection
adocn.Open strsqlserver
End If
End Sub
(二)下载
本实例使用三个API函数完成下载功能。
1.api函数GetUrlCacheEntryInfo。
该函数的作用是判断用户终端IE缓存是否有FTP服务器url记录。该函数的声明如下:
Private Declare Function GetUrlCacheEntryInfo Lib "winINet.dll" Alias "GetUrlCacheEntryInfoA" (ByVal sUrlName As String, lpCacheEntryInfo As Any,lpdwCacheEntryInfoBufferSize As Long) As Long
2.api函数DeleteUrlCacheEntry。
该函数的作用是删除用户终端IE缓存中的FTP服务器url记录。这是必须的,如果没有删除IE缓存信息,API函数URLDownloadToFile将从本地IE缓存下载文件,导致程序升级失败。该函数的声明如下:
Private Declare Function DeleteUrlCacheEntry Lib "winINet.dll" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long
3.api函数声明。
api函数URLDownloadToFile的作用是从远程服务器下载文件到本地。该函数的声明如下:
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
(三)使用新版应用程序更换原应用程序
这个问题比较有趣,因为它要求程序运行时将自己从系统删除。我们知道,正在运行的程序是无法删除或替换的。解决的方案是写两个程序,一个是主程序,一个是升级程序,所有升级任务都由升级程序完成。
二、软件自动在线升级的步骤
(一)启动主程序,与SQL Server2000服务器数据库取得连接,判断软件是否需要更新,如果不需要更新,继续运行主程序,否则运行升级程序,并中断主程序运行。
(二)升级程序从FTP服务器下载最新文件。
(三)替换旧文件,关闭升级程序,升级完成。
三、基于VB6+ SQL Server2000局域网环境下实现软件自动在线升级的主要代码
(一)主程序启动时判断是否需要升级的主要代码如下
Private Sub Form_Load()
Dim URL As String
Dim strsql As String
Dim bb_old As String
Dim bb_new As String
Dim adors As New Recordset
frmLogin.Caption = "登录程序版本" & App.Major & "." & App.Minor & "." & App.Revision
adors.ActiveConnection = adocn
strsql = "select * from bbsj"
adors.Open strsql
If Not adors.EOF Then
bb_old = App.Major & "." & App.Minor & "." & App.Revision
bb_new = adors("bbsj")
If Val(Right(Trim(bb_old), 2)) < Val(Right(Trim(bb_new), 2)) Then
MsgBox"程序有新版本,现在开始更新。"+ Chr(13)+"当前版本:"+bb_old+Chr(13)+"新版本:"+bb_new,vbOKOnly
Dim a As String
if right(app.path,1)=”\” then
a=app.path + “update.exe”
else
a = App.Path + "\update.exe"
end if
Shell a "调用升级程序update.exe
End "结束主程序
End If
End If
End Sub
(二)升级程序的主要代码如下
Private Declare Function GetUrlCacheEntryInfo Lib "winINet.dll" Alias "GetUrlCacheEntryInfoA" (ByVal sUrlName As String, lpCacheEntryInfo As Any, lpdwCacheEntryInfoBufferSize As Long) As Long
Private Declare Function DeleteUrlCacheEntry Lib "winINet.dll" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private Sub Form_Load()
Dim bb As String
bb = App.Major & "." & App.Minor & "." & App.Revision
Dim URL As String
Dim ret As Long
URL = "ftp://10.88.64.119/赠品管理l.exe"
If (InCache(URL)) Then
DeleteCacheURL URL
End If
ret = URLDownloadToFile(0, "ftp://10.88.64.119/赠品管理l.exe", App.Path & "\赠品管理l.exe",0,0)
If ret =0 Then
MsgBox"主程序升级成功。",0,bb
Else
MsgBox"主程序升级失败。",0,bb
End If
四、结束语
在整个系统的开发期间,所有的调研分析、设计和编码都基本上是自己通过自学独立完成的。通过本次设计,重新认识了软件工程在软件开发过程中的重要意义和作用,了解了软件开发的一般过程,掌握了软件开发的基本方法。
参考文献:
[1]廖望.SQL Server2000案例教程[M].冶金工业出版社,2004,4
[2]刘世峰.Visual Basic程序设计[M].中央广播电视大学出版社,2004,7
上一篇:校园局域网信息安全与病毒防治分析
下一篇:局域网网速变慢的原因及对策