You can retrieve the file version using version information API functions. The following code shows how to query the version information resource and extract the desired data.
___
[tt]
Option Explicit
Private Declare Function VerQueryValue Lib "version" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Long, puLen As Long) As Long
Private Declare Function GetFileVersionInfoSize Lib "version" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
Private Declare Function GetFileVersionInfo Lib "version" Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwHandle As Long, ByVal dwLen As Long, lpData As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Type VS_FIXEDFILEINFO
dwSignature As Long
dwStrucVersion As Long
dwFileVersionMS As Long '<-file version
dwFileVersionLS As Long '<-stored here
dwProductVersionMS As Long
dwProductVersionLS As Long
dwFileFlagsMask As Long
dwFileFlags As Long
dwFileOS As Long
dwFileType As Long
dwFileSubtype As Long
dwFileDateMS As Long
dwFileDateLS As Long
End Type
Function GetFileVersion(FileName As String) As String
Dim VerInfoSize As Long, Buffer() As Byte
Dim lpData As Long, cbData As Long
Dim vsffi As VS_FIXEDFILEINFO, Ver(3) As Integer
'Query the size of the version info data
VerInfoSize = GetFileVersionInfoSize(FileName, ByVal 0)
If VerInfoSize = 0 Then Exit Function
'Create the version info buffer and query the data
ReDim Buffer(0 To VerInfoSize - 1)
If GetFileVersionInfo(FileName, 0, VerInfoSize, Buffer(0)) = 0 Then Exit Function
'Query the VS_FIXEDFILEINFO structure
If VerQueryValue(Buffer(0), "\", lpData, cbData) = 0 Then Exit Function
CopyMemory vsffi, ByVal lpData, cbData
'copy the file version bytes to integer array for easy formatting
CopyMemory Ver(0), vsffi.dwFileVersionMS, 8
'return the file version
GetFileVersion = Ver(1) & "." & Ver(0) & "." & Ver(3) & "." & Ver(2)
End Function
Private Sub Form_Load()
MsgBox GetFileVersion("calc.exe")
End
End Sub[/tt]
___
As far as the result of the function is concerned, there is absolutely no difference in result of this function or the code provided by George.
The only difference is that his function uses FSO, and thats why its brief, whereas my function uses standard API functions to achieve the same.