Here's how to Extract all File Info, including Version, this only works for 32-bit Files..
Code:
Private 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
Private Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
Private Declare Function VerQueryValue Lib "Version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, puLen As Long) As Long
Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (lpString1 As Any, lpString2 As Any) As Long
Private Sub Command1_Click()
Dim sVerInfo(7) As String
Dim sInfo As String
Dim sValue As String
Dim sFile As String
Dim sData() As Byte
Dim lSize As Long
Dim lPointer As Long
Dim iIndex As Integer
On Error GoTo OpenError
With CommonDialog1
.CancelError = True
.Filter = "DLL's|*.DLL"
.ShowOpen
sFile = .FileName
End With
Text1 = ""
'Get the Length of the FileVersion Information
lSize = GetFileVersionInfoSize(sFile, ByVal 0&)
'Create a Buffer to hold the Version Info
ReDim sData(lSize)
'Get the Version Info
If GetFileVersionInfo(sFile, 0&, lSize, sData(0)) Then
'Extract the Details of the Version Info
sVerInfo(0) = "CompanyName"
sVerInfo(1) = "FileDescription"
sVerInfo(2) = "FileVersion"
sVerInfo(3) = "InternalName"
sVerInfo(4) = "LegalCopyright"
sVerInfo(5) = "OriginalFileName"
sVerInfo(6) = "ProductName"
sVerInfo(7) = "ProductVersion"
For iIndex = 0 To 7
sInfo = "\StringFileInfo\040904E4\" & sVerInfo(iIndex)
If VerQueryValue(sData(0), sInfo, lPointer, lSize) Then
sValue = Space(lSize)
lstrcpy ByVal sValue, ByVal lPointer
Text1.SelText = sVerInfo(iIndex) & ": " & sValue
Text1.SelText = vbCrLf
End If
Next
End If
OpenError:
End Sub
Alternatively, here's a Wrapper I wrote to enable you to Retrieve 16bit Version Info as well as 32bit:
Code:
Private 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
Private Declare Function GetFileVersionInfoSize Lib "version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
Public Function GetVersion(ByVal sFile As String) As String
On Error GoTo Err_NoVer
Dim sVerInfo As String
Dim iVerLen As Integer
Dim iVerPos As Long
iVerLen = GetFileVersionInfoSize(sFile, 0&)
sVerInfo = Space(iVerLen)
Call GetFileVersionInfo(sFile, 0&, iVerLen, ByVal sVerInfo)
iVerPos = InStr(sVerInfo, "FileVersion") + 12
If iVerPos = 12 Then
'Check for 32bit Dll
sVerInfo = StrConv(sVerInfo, vbFromUnicode)
iVerPos = InStr(sVerInfo, "FileVersion") + 13
End If
GetVersion = Mid(sVerInfo, iVerPos, InStr(iVerPos, sVerInfo, Chr(0)) - 1)
Err_NoVer:
End Function
Private Sub Command1_Click()
On Error GoTo UserCancelled
With CommonDialog1
.DialogTitle = "Select a File.."
.CancelError = True
.Filter = "All Files|*.dll"
.ShowOpen
Caption = GetVersion(.FileName)
End With
UserCancelled:
End Sub
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
Certified AllExperts Expert
[This message has been edited by Aaron Young (edited 02-12-2000).]