Access – Detekcija verzije Office-a i njegovih zakrpa

Kada krajnjim korisnicima isporučujete aplikacije urađene u Access okruženju, vrlo je važno da detektujte koja je verzija Office-a prisutna na mašini i da li je instalirana neka od mnogobrojnih servisnih zakrpa. Nažalost, Microsoft nam nije obezbedio nijedan način za detektovanje instaliranosti servisnih zakrpa (kao što su Office Service Pack-ovi) preko programskog koda. Jedna od zaobilaznih mogućnosti da se prevaziđe ovaj problem jeste iščitavanje informacija o verziji, smeštenih u izvršne fajlove aplikacija Office paketa. U tabeli na slici možete videti informacije o verziji koje su preuzete sa jedne postojeće mašine. Zato ćemo vam predstaviti funkcije za dobijanje ovih informacija:


Private Type VS_FIXEDFILEINFO
dwSignature As Long
dwStrucVersion As Long
dwFileVersionMS As Long
dwFileVersionLS As Long
dwProductVersionLS As Long
dwFileFlagsMask As Long
dwProductVersionMS As Long
dwFileFlags As Long
dwFileOS As Long
dwFileType As Long
dwFileSubtype As Long
dwFileDateMS As Long
dwFileDateLS As Long
End Type

Private Declare Function apiGetFileVersionInfoSize _
Lib "version.dll" Alias "GetFileVersionInfoSizeA" _
(ByVal lptstrFilename As String, _
lpdwHandle As Long) As Long

Private Declare Function apiGetFileVersionInfo Lib _
"version.dll" Alias "GetFileVersionInfoA" _
(ByVal lptstrFilename As String, _
ByVal dwHandle As Long, _
ByVal dwLen As Long, _
lpData As Any) As Long

Private Declare Function apiVerQueryValue Lib _
"version.dll" Alias "VerQueryValueA" _
(pBlock As Any, _
ByVal lpSubBlock As String, _
lplpBuffer As Long, _
puLen As Long) _
As Long

Private Declare Sub sapiCopyMem _
Lib "kernel32" Alias "RtlMoveMemory" _
(Destination As Any, _
Source As Any, _
ByVal Length As Long)

Function fGetProductVersion(strExeFullPath As String)
As String
On Error GoTo ErrHandler
Dim lngSize As Long
Dim lngRet As Long
Dim pBlock() As Byte
Dim lpfi As VS_FIXEDFILEINFO
Dim lppBlock As Long

lngSize = apiGetFileVersionInfoSize( _
strExeFullPath, _
lngRet)
If lngSize Then
ReDim pBlock(lngSize)
lngRet = apiGetFileVersionInfo(strExeFullPath, 0, _
lngSize, pBlock(0))
If Not lngRet = 0 Then
lngRet = apiVerQueryValue(pBlock(0), _
"", lppBlock, lngSize)
Call sapiCopyMem(lpfi, ByVal lppBlock, lngSize)
With lpfi
fGetProductVersion =
HIWord(.dwFileVersionMS) & "." & _
LOWord(.dwFileVersionMS) & "." &
HIWord(.dwFileVersionLS) & "." & _
LOWord(.dwFileVersionLS)
End With
End If
End If

ExitHere:
Erase pBlock
Exit Function
ErrHandler:
Resume ExitHere
End Function

Private Function LOWord(dw As Long) As Integer

If dw And &H8000& Then
LOWord = dw Or &HFFFF0000
Else
LOWord = dw And &HFFFF&
End If

End Function

Private Function HIWord(dw As Long) As Integer

HIWord = (dw And &HFFFF0000) &H10000

End Function

Pratite Krstaricu na www.krstarica.com