PDA

Vollständige Version anzeigen : API: GetFileVersionInfo


goldstar
09.11.2000, 11:53
hi!

kann mir jemand ein beispiel in vba kredenzen, wie ich mittels dieser funktion (oder einer beliebigen anderen) die versionsnummern von ddl's und exe's bekomme. die doku hat mir dieses geheimnis leider nicht verraten bzw. mein access schmiert beim aufruf der funktion jedesmal ab :(

ciao
carsten

Manuela Kulpa
09.11.2000, 14:29
Hallo Carsten!

Ein kleiner Tipp am Rande ;), hier wirst du fast immer fündig, wenn's um API geht: http://www.mvps.org/vbnet

Nichts desto ein kleines Beispiel, auf deine Bedürfnisse gestrickt (habe ich natürlich aus VBnet)

Erstell dir ein neues Modul und kopiere folgendes rein:

Public Type VS_FIXEDFILEINFO
dwSignature As Long
dwStrucVersion As Long 'e.g. 0x00000042 = "0.42"
dwFileVersionMS As Long 'e.g. 0x00030075 = "3.75"
dwFileVersionLS As Long 'e.g. 0x00000031 = "0.31"
dwProductVersionMS As Long 'e.g. 0x00030010 = "3.10"
dwProductVersionLS As Long 'e.g. 0x00000031 = "0.31"
dwFileFlagsMask As Long '= 0x3F for version "0.42"
dwFileFlags As Long 'e.g. VFF_DEBUG Or VFF_PRERELEASE
dwFileOS As Long 'e.g. VOS_DOS_WINDOWS16
dwFileType As Long 'e.g. VFT_DRIVER
dwFileSubtype As Long 'e.g. VFT2_DRV_KEYBOARD
dwFileDateMS As Long 'e.g. 0
dwFileDateLS As Long 'e.g. 0
End Type


Public Declare Function GetFileVersionInfoSize Lib "Version.dll" _
Alias "GetFileVersionInfoSizeA" _
(ByVal lptstrFilename As String, _
lpdwHandle As Long) As Long


Public Declare Function GetFileVersionInfo Lib "Version.dll" _
Alias "GetFileVersionInfoA" _
(ByVal lptstrFilename As String, _
ByVal dwHandle As Long, _
ByVal dwLen As Long, _
lpData As Any) As Long


Public Declare Function VerQueryValue Lib "Version.dll" _
Alias "VerQueryValueA" _
(pBlock As Any, _
ByVal lpSubBlock As String, _
lplpBuffer As Any, nVerSize As Long) As Long


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


Public Function GetFileVersion(sDriverFile As String) As String


Dim FI As VS_FIXEDFILEINFO
Dim sBuffer() As Byte
Dim nBufferSize As Long
Dim lpBuffer As Long
Dim nVerSize As Long
Dim nUnused As Long
Dim tmpVer As String


'GetFileVersionInfoSize determines whether the operating
'system can obtain version information about a specified
'file. If version information is available, it returns
'the size in bytes of that information. As with other
'file installation functions, GetFileVersionInfoSize
'works only with Win32 file images.
'
'A empty variable must be passed as the second
'parameter, which the call returns 0 in.
nBufferSize = GetFileVersionInfoSize(sDriverFile, nUnused)


If nBufferSize > 0 Then


'create a buffer to receive file-version
'(FI) information.
ReDim sBuffer(nBufferSize)
Call GetFileVersionInfo(sDriverFile, 0&, nBufferSize, sBuffer(0))


'VerQueryValue function returns selected version info
'from the specified version-information resource. Grab
'the file info and copy it into the VS_FIXEDFILEINFO structure.
Call VerQueryValue(sBuffer(0), "\", lpBuffer, nVerSize)
Call CopyMemory(FI, ByVal lpBuffer, Len(FI))


'extract the file version from the FI structure
tmpVer = Format$(HiWord(FI.dwFileVersionMS)) & "." & _
Format$(LoWord(FI.dwFileVersionMS), "00") & "."


If FI.dwFileVersionLS > 0 Then
tmpVer = tmpVer & Format$(HiWord(FI.dwFileVersionLS), "00") & "." & _
Format$(LoWord(FI.dwFileVersionLS), "00")
Else
tmpVer = tmpVer & Format$(FI.dwFileVersionLS, "0000")
End If


End If


GetFileVersion = tmpVer

End Function


Function HiWord(dw As Long) As Long


If dw And &H80000000 Then
HiWord = (dw \ 65535) - 1
Else: HiWord = dw \ 65535
End If

End Function


Function LoWord(dw As Long) As Long

If dw And &H8000& Then
LoWord = &H8000 Or (dw And &H7FFF&)
Else: LoWord = dw And &HFFFF&
End If

End Function

Aufruf mit z.B. GetFileVersion("G:\WINNT\explorer.exe")

LLAP