Link to home
Start Free TrialLog in
Avatar of parduz
parduz

asked on

EXE & DLL version

How to extract the version number of a EXE or DLL?
I means the number that ou can see if you click property->version
on a EXE or DLL.
Thanks.
Avatar of Ruchi
Ruchi

this is from the web.

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
                          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
                              'No Version Info, Check for 32bit File -
                              '32Bit Files Return Unicode Strings
                              sVerInfo = StrConv(sVerInfo, vbFromUnicode)
                              iVerPos = InStr(sVerInfo, "FileVersion") + 13
                          End If
                          If iVerPos > 12 Then GetVersion = GetVersion & Mid(sVerInfo, iVerPos, InStr(iVerPos, sVerInfo, Chr(0)) - 1)
                      End Function
                      Private Sub Command1_Click()
                          On Error GoTo UserCancelled
                          With CommonDialog1
                              .DialogTitle = "Select a File.."
                              .CancelError = True
                              .Filter = "All Files|*.dll;*.exe"
                              .ShowOpen
                              Caption = GetVersion(.FileName)
                          End With
                      UserCancelled:
                      End Sub
this is the above same code. add a command button on the form.

Option Explicit

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
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
    'No Version Info, Check for 32bit File -
    '32Bit Files Return Unicode Strings
    sVerInfo = StrConv(sVerInfo, vbFromUnicode)
    iVerPos = InStr(sVerInfo, "FileVersion") + 13
End If
If iVerPos > 12 Then GetVersion = GetVersion & Mid(sVerInfo, iVerPos, InStr(iVerPos, sVerInfo, Chr(0)) - 1)
End Function
Private Sub Command1_Click()
On Error GoTo UserCancelled
With CommonDialog1
    .DialogTitle = "Select a File.."
    .CancelError = True
    .Filter = "All Files|*.dll;*.exe"
    .ShowOpen
    Caption = GetVersion(.FileName)
End With
UserCancelled:
End Sub
ASKER CERTIFIED SOLUTION
Avatar of Ruchi
Ruchi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of parduz

ASKER

All right.
Due to a lot of job to do, i check all your coments in the next week.
Thanks to all for the help
Again, I am looking forward to your comments.
Avatar of parduz

ASKER

Sorry for the delay, my job is a nightmare.
Thanx again