'==================================================================================================================== 'Public Function CheckOnlineUpgrade(DBCon as ADODB.Connection) as Boolean ' ' If this returns true immediately "End" current App. ' ' DBCon must evaluate to an active and open connection to a data source with read access to the following table ' ' CREATE TABLE App_Versions ( ' app_title varchar(255) not null, -- The title of the VB application as determined by App.Title ' major int not null, -- The major version as determined by App.Major (requires upgrade) ' minor int not null, -- The minor version as determined by App.Minor (optional upgrade) ' revision int not null, -- The revision number as determined by App.Revision (silent upgrade) ' upgrade_url varchar(255) not null) -- The full URL to a executable upgrade routine ' '-------------------------------------------------------------------------------------------------------------------- ' System Requirements: ' Microsoft Visual Basic Runtime 6.0 or higher ' Microsoft Internet Explorer 4.0 or higher ' Microsoft Data Access Components 2.0 or higher ' Sage Analytic Upgrade Agent 1.0 or higher ' ' Make sure to reference "Microsoft ActiveX Data Objects 2.0 Library" or higher in your Visual Basic project ' ' Written by: Sage Analytic (http://www.sageanalytic.com) ' 02/23/2001 ' '==================================================================================================================== Declare Function GetCurrentProcessId Lib "kernel32" () As Long Public Function CheckOnlineUpgrade(DBCon As ADODB.Connection) As Boolean Dim UpgradeAvailable As Boolean Dim UpgradeRequired As Boolean Dim AppRS As New ADODB.Recordset Dim LocalFilename As String Dim RemoteFilename As String UpgradeAvailable = False UpgradeRequired = False AppRS.Open "SELECT major, minor, revision, upgrade_url FROM App_Versions WHERE app_title = '" + App.Title + "'", DBCon If Not AppRS.EOF Then RemoteFilename = AppRS("upgrade_url") LocalFilename = Trim(App.Path) + "\" + Mid(RemoteFilename, InStrRev(RemoteFilename, "/") + 1) If AppRS("major").Value > App.Major Then ' If Major has changed then an upgrade is mandatory UpgradeAvailable = True UpgradeRequired = True ElseIf AppRS("major").Value = App.Major And AppRS("minor").Value > App.Minor Then ' If only Minor has changed then an upgrade is optional UpgradeAvailable = True UpgradeRequired = False ElseIf AppRS("major").Value = App.Major And AppRS("minor").Value = App.Minor And AppRS("revision").Value > App.Revision Then ' If only Revision has changed then an upgrade is optional and do not even prompt the user UpgradeAvailable = False UpgradeRequired = False End If End If If UpgradeRequired Then CheckOnlineUpgrade = True If MsgBox("An mandatory upgrade for this application is available. " + vbCrLf + _ "The new version will be downloaded and installed automatically for you. " + vbCrLf + _ "You will not be able to run this application until the upgrade has been performed.", _ vbOKCancel + vbExclamation, "Application Version Check") = vbCancel Then UpgradeRequired = False End If ElseIf UpgradeAvailable Then If MsgBox("An upgrade for this application is available. " + vbCrLf + vbCrLf + _ "Do you wish to download and install the upgrade at this time?", vbYesNo + vbExclamation, _ "Application Version Check") = vbYes Then CheckOnlineUpgrade = True UpgradeRequired = True End If End If If UpgradeRequired Then On Error Resume Next If Shell("""" + Trim(App.Path) + "\UpgradeAgent.exe"" /R " + RemoteFilename + _ " /L """ + LocalFilename + """" + _ " /A """ + App.Title + """" + _ " /E """ + Trim(App.Path) + "\" + Trim(App.EXEName) + ".exe""" + _ " /P " + CStr(GetCurrentProcessId()) + " /D", vbNormalFocus) = 0 Then MsgBox "ERROR: The upgrade agent could not be started.", vbCritical, "Application Version Check" End If End If End Function '==============================================================================================