Bob,
Give this a try ....
Put this code in a .BAS file
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
'
****************************************************************************
*******
' Version...
'
****************************************************************************
*******
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 Byte) As Long
Public Declare Function VerQueryValue Lib "version.dll" Alias
"VerQueryValueA" (pBlock As Byte, ByVal lpSubBlock As String, lplpBuffer As
Long, puLen As Long) As Long
Private Function GetVersionInfo(ByVal sApp As String, sFileVer As String) As
Boolean
Dim udtFileInfo As VS_FIXEDFILEINFO
Dim lpdwHandle As Long
Dim lSize As Long
Dim di As Long
Dim lpData() As Byte
Dim FileAddress As Long
Dim FileLen As Long
Dim sNetwork As String
Dim nMajorMS As Integer
Dim nMinorMS As Integer
Dim nMinorLS As Integer
On Error GoTo err_Handler
sFileVer = ""
GetVersionInfo = False
' Determine if version information is present, and
' if so how large a buffer is needed to hold it.
lSize = GetFileVersionInfoSize(sApp, lpdwHandle)
' Version info is unlikely to ever be greater than 64k
' but check anyway. If it was larger than 64k, we would
' need to allocate a huge buffer instead. Note, we
' are only using an approximation to 64k here to take
' into account the VB string overhead.
If lSize > 64000 Then lSize = 64000
ReDim lpData(lSize + 1)
' Load the string with the version information
di = GetFileVersionInfo(sApp, lpdwHandle, lSize, lpData(0))
If di = 0 Then
'MsgBox "Unable to locate file : " & sApp
GoTo exit_Function
End If
di = VerQueryValue(lpData(0), "\", FileAddress, FileLen)
If di = 0 Then
'MsgBox "No fixed version information in this file"
GoTo exit_Function
End If
' Copy the fixed file info into the structure
Call MoveMemoryStrToUdt(udtFileInfo, FileAddress, FileLen)
nMajorMS = CInt(udtFileInfo.dwFileVersionMS / &H10000)
nMinorMS = CInt(udtFileInfo.dwFileVersionMS And &HFFFF&)
nMinorLS = CInt(udtFileInfo.dwFileVersionLS And &HFFFF&)
sFileVer = Trim$(Str$(nMajorMS)) + "." + Trim$(Str$(nMinorMS)) + "." +
Trim$(Str$(nMinorLS))
GetVersionInfo = True
exit_Function:
Exit Function
err_Handler:
Err.Clear
End Function
--KK
Quote:
> Hi all,
> Is that any window API that return the version of an EXE file?
> Or what are the steps I need to accomplish that?
> I am programming using VC5,6 and VB5,6 on NT4/WS/SVR
> Thanks,
> Bob.