Finding file version.

If i know the path to an exe, how can i find its version numbers?
wormboy__6Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Bob LearnedConnect With a Mentor Commented:
Sorry, sometimes it is easier to give you all that I have and let you decide what you want.  

Here's a stripped down version for just file version information.

Option Explicit

' Place the following code in a single class module called Version.cls:
'
' The Global constants below are defined in the VER.H header file, also
' included in Microsoft C/C++ 7.0, and the Windows SDK.
'
' **** Global variables used in both forms ****

' Calling convention:
'   Dim oVersion as New Version
'

'   Call oVersion.GetVersion("C:\WINNT", "EXPLORER.EXE" )

Public FileVersion As String

Private Type VS_FIXEDFILEINFO

   dwSignature As Long
   dwStrucVersionl As Integer     '  e.g. = &h0000 = 0
   dwStrucVersionh As Integer     '  e.g. = &h0042 = .42
   dwFileVersionMSl As Integer    '  e.g. = &h0003 = 3
   dwFileVersionMSh As Integer    '  e.g. = &h0075 = .75
   dwFileVersionLSl As Integer    '  e.g. = &h0000 = 0
   dwFileVersionLSh As Integer    '  e.g. = &h0031 = .31
   dwProductVersionMSl As Integer '  e.g. = &h0003 = 3
   dwProductVersionMSh As Integer '  e.g. = &h0010 = .1
   dwProductVersionLSl As Integer '  e.g. = &h0000 = 0
   dwProductVersionLSh As Integer '  e.g. = &h0031 = .31
   dwFileFlagsMask As Long        '  = &h3F 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

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 Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
   (dest As Any, ByVal Source As Long, ByVal length As Long)

Public Sub GetVersion(sDirectory As String, sFileName As String)
   
'*** Get Version Info ****

Dim lRtn              As Long
Dim lDummy            As Long
Dim sBuffer()         As Byte
Dim lBufferLen        As Long
Dim lVerPointer       As Long
Dim udtVerBuffer      As VS_FIXEDFILEINFO
Dim lVerbufferLen     As Long
Dim sFullFileName     As String

   '*** Build full name from sDirectory and filename ***
   sFullFileName = sDirectory & "\" & sFileName

   '*** Get size ****
   lBufferLen = GetFileVersionInfoSize(sFullFileName, lDummy)
   If lBufferLen < 1 Then
      MsgBox "No Version Info available!"
      Exit Sub
   End If

   '**** Store info to udtVerBuffer struct ****
   ReDim sBuffer(lBufferLen)
   lRtn = GetFileVersionInfo(sFullFileName, 0&, lBufferLen, sBuffer(0))
   lRtn = VerQueryValue(sBuffer(0), "\", lVerPointer, lVerbufferLen)
   CopyMemory udtVerBuffer, lVerPointer, Len(udtVerBuffer)

   '**** Determine File Version number ****
   FileVersion = Format$(udtVerBuffer.dwFileVersionMSh) & "." & _
      Format$(udtVerBuffer.dwFileVersionMSl) & "." & _
      Format$(udtVerBuffer.dwFileVersionLSh) & "." & _
      Format$(udtVerBuffer.dwFileVersionLSl)
   
End Sub

0
 
Bob LearnedCommented:
Option Explicit

' Place the following code in a single class module called Version.cls:
'
' The Global constants below are defined in the VER.H header file, also
' included in Microsoft C/C++ 7.0, and the Windows SDK.
'
' **** Global variables used in both forms ****

' Calling convention:
'   Dim oVersion as New Version
'

'   Call oVersion.GetVersion("C:\WINNT", "EXPLORER.EXE" )

Public FileName As String
Public Directory As String
Public FullFileName As String
Public StructVersion As String
Public FileVersion As String
Public ProductVersion As String
Public FileFlags As String
Public FileOS As String
Public FileType As String
Public FileSubType As String

Private Type VS_FIXEDFILEINFO

   dwSignature As Long
   dwStrucVersionl As Integer     '  e.g. = &h0000 = 0
   dwStrucVersionh As Integer     '  e.g. = &h0042 = .42
   dwFileVersionMSl As Integer    '  e.g. = &h0003 = 3
   dwFileVersionMSh As Integer    '  e.g. = &h0075 = .75
   dwFileVersionLSl As Integer    '  e.g. = &h0000 = 0
   dwFileVersionLSh As Integer    '  e.g. = &h0031 = .31
   dwProductVersionMSl As Integer '  e.g. = &h0003 = 3
   dwProductVersionMSh As Integer '  e.g. = &h0010 = .1
   dwProductVersionLSl As Integer '  e.g. = &h0000 = 0
   dwProductVersionLSh As Integer '  e.g. = &h0031 = .31
   dwFileFlagsMask As Long        '  = &h3F 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

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 Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
   (dest As Any, ByVal Source As Long, ByVal length As Long)

' ===== From Win32 Ver.h =================
' ----- VS_VERSION.dwFileFlags -----

Private Const VS_FFI_SIGNATURE = &HFEEF04BD
Private Const VS_FFI_STRUCVERSION = &H10000
Private Const VS_FFI_FILEFLAGSMASK = &H3F&

' ----- VS_VERSION.dwFileFlags -----

Private Const VS_FF_DEBUG = &H1
Private Const VS_FF_PRERELEASE = &H2
Private Const VS_FF_PATCHED = &H4
Private Const VS_FF_PRIVATEBUILD = &H8
Private Const VS_FF_INFOINFERRED = &H10
Private Const VS_FF_SPECIALBUILD = &H20

' ----- VS_VERSION.dwFileOS -----

Private Const VOS_UNKNOWN = &H0
Private Const VOS_DOS = &H10000
Private Const VOS_OS216 = &H20000
Private Const VOS_OS232 = &H30000
Private Const VOS_NT = &H40000
Private Const VOS__BASE = &H0
Private Const VOS__WINDOWS16 = &H1
Private Const VOS__PM16 = &H2
Private Const VOS__PM32 = &H3
Private Const VOS__WINDOWS32 = &H4

Private Const VOS_DOS_WINDOWS16 = &H10001
Private Const VOS_DOS_WINDOWS32 = &H10004
Private Const VOS_OS216_PM16 = &H20002
Private Const VOS_OS232_PM32 = &H30003
Private Const VOS_NT_WINDOWS32 = &H40004


' ----- VS_VERSION.dwFileType -----

Private Const VFT_UNKNOWN = &H0
Private Const VFT_APP = &H1
Private Const VFT_DLL = &H2
Private Const VFT_DRV = &H3
Private Const VFT_FONT = &H4
Private Const VFT_VXD = &H5
Private Const VFT_STATIC_LIB = &H7

' ----- VS_VERSION.dwFileSubtype for VFT_WINDOWS_DRV -----

Private Const VFT2_UNKNOWN = &H0
Private Const VFT2_DRV_PRINTER = &H1
Private Const VFT2_DRV_KEYBOARD = &H2
Private Const VFT2_DRV_LANGUAGE = &H3
Private Const VFT2_DRV_DISPLAY = &H4
Private Const VFT2_DRV_MOUSE = &H5
Private Const VFT2_DRV_NETWORK = &H6
Private Const VFT2_DRV_SYSTEM = &H7
Private Const VFT2_DRV_INSTALLABLE = &H8
Private Const VFT2_DRV_SOUND = &H9
Private Const VFT2_DRV_COMM = &HA

Private Const VS_VERSION_INFO = 1
Private Const VS_USER_DEFINED = 100

' ----- VS_VERSION.dwFileSubtype for VFT_WINDOWS_FONT ----- */
Private Const VFT_FONT_RASTER = &H1
Private Const VFT_FONT_VECTOR = &H2
Private Const VFT_FONT_TRUETYPE = &H3

' ----- VerFindFile() flags ----- */
Private Const VFFF_ISSHAREDFILE = &H1

Private Const VFF_CURNEDEST = &H1
Private Const VFF_FILEINUSE = &H2
Private Const VFF_BUFFTOOSMALL = &H4

' ----- VerInstallFile() flags ----- */
Private Const VIFF_FORCEINSTALL = &H1
Private Const VIFF_DONTDELETEOLD = &H2

Private Const VIF_TEMPFILE = &H1
Private Const VIF_MISMATCH = &H2
Private Const VIF_SRCOLD = &H4

Private Const VIF_DIFFLANG = &H8
Private Const VIF_DIFFCODEPG = &H10
Private Const VIF_DIFFTYPE = &H20

Private Const VIF_WRITEPROT = &H40
Private Const VIF_FILEINUSE = &H80
Private Const VIF_OUTOFSPACE = &H100
Private Const VIF_ACCESSVIOLATION = &H200
Private Const VIF_SHARINGVIOLATION = &H400
Private Const VIF_CANNOTCREATE = &H800
Private Const VIF_CANNOTDELETE = &H1000
Private Const VIF_CANNOTRENAME = &H2000
Private Const VIF_CANNOTDELETECUR = &H4000
Private Const VIF_OUTOFMEMORY = &H8000

Private Const VIF_CANNOTREADSRC = &H10000
Private Const VIF_CANNOTREADDST = &H20000

Private Const VIF_BUFFTOOSMALL = &H40000

Public Sub GetVersion(sDirectory As String, sFileName As String)
   
'*** Get Version Info ****

Dim lRtn              As Long
Dim lDummy            As Long
Dim sBuffer()         As Byte
Dim lBufferLen        As Long
Dim lVerPointer       As Long
Dim udtVerBuffer      As VS_FIXEDFILEINFO
Dim lVerbufferLen     As Long
Dim sFullFileName     As String

   '*** Build full name from sDirectory and filename ***
   sFullFileName = sDirectory & "\" & sFileName

   '*** Get size ****
   lBufferLen = GetFileVersionInfoSize(sFullFileName, lDummy)
   If lBufferLen < 1 Then
      MsgBox "No Version Info available!"
      Exit Sub
   End If

   '**** Store info to udtVerBuffer struct ****
   ReDim sBuffer(lBufferLen)
   lRtn = GetFileVersionInfo(sFullFileName, 0&, lBufferLen, sBuffer(0))
   lRtn = VerQueryValue(sBuffer(0), "\", lVerPointer, lVerbufferLen)
   CopyMemory udtVerBuffer, lVerPointer, Len(udtVerBuffer)

   '**** Determine Structure Version number - NOT USED ****
   StructVersion = Format$(udtVerBuffer.dwStrucVersionh) & "." & _
      Format$(udtVerBuffer.dwStrucVersionl)

   '**** Determine File Version number ****
   FileVersion = Format$(udtVerBuffer.dwFileVersionMSh) & "." & _
      Format$(udtVerBuffer.dwFileVersionMSl) & "." & _
      Format$(udtVerBuffer.dwFileVersionLSh) & "." & _
      Format$(udtVerBuffer.dwFileVersionLSl)

   '**** Determine Product Version number ****
   ProductVersion = Format$(udtVerBuffer.dwProductVersionMSh) & "." & _
      Format$(udtVerBuffer.dwProductVersionMSl) & "." & _
      Format$(udtVerBuffer.dwProductVersionLSh) & "." & _
      Format$(udtVerBuffer.dwProductVersionLSl)

   '**** Determine Boolean attributes of File ****
   FileFlags = ""
   If udtVerBuffer.dwFileFlags And VS_FF_DEBUG _
      Then FileFlags = "Debug "
   If udtVerBuffer.dwFileFlags And VS_FF_PRERELEASE _
      Then FileFlags = FileFlags & "PreRel "
   If udtVerBuffer.dwFileFlags And VS_FF_PATCHED _
      Then FileFlags = FileFlags & "Patched "
   If udtVerBuffer.dwFileFlags And VS_FF_PRIVATEBUILD _
      Then FileFlags = FileFlags & "Private "
   If udtVerBuffer.dwFileFlags And VS_FF_INFOINFERRED _
      Then FileFlags = FileFlags & "Info "
   If udtVerBuffer.dwFileFlags And VS_FF_SPECIALBUILD _
      Then FileFlags = FileFlags & "Special "
   If udtVerBuffer.dwFileFlags And VFT2_UNKNOWN _
      Then FileFlags = FileFlags + "Unknown "

   '**** Determine OS for which file was designed ****
   Select Case udtVerBuffer.dwFileOS
      Case VOS__WINDOWS32
        FileOS = "Win32"
      Case VOS_DOS_WINDOWS16
        FileOS = "DOS-Win16"
      Case VOS_DOS_WINDOWS32
        FileOS = "DOS-Win32"
      Case VOS_OS216_PM16
        FileOS = "OS/2-16 PM-16"
      Case VOS_OS232_PM32
        FileOS = "OS/2-16 PM-32"
      Case VOS_NT_WINDOWS32
        FileOS = "NT-Win32"
      Case Else
        FileOS = "Unknown"
   End Select
   
   Select Case udtVerBuffer.dwFileType
      Case VFT_APP
         FileType = "App"
      Case VFT_DLL
         FileType = "DLL"
      Case VFT_DRV
         FileType = "Driver"
         Select Case udtVerBuffer.dwFileSubtype
            Case VFT2_DRV_PRINTER
               FileSubType = "Printer drv"
            Case VFT2_DRV_KEYBOARD
               FileSubType = "Keyboard drv"
            Case VFT2_DRV_LANGUAGE
               FileSubType = "Language drv"
            Case VFT2_DRV_DISPLAY
               FileSubType = "Display drv"
            Case VFT2_DRV_MOUSE
               FileSubType = "Mouse drv"
            Case VFT2_DRV_NETWORK
               FileSubType = "Network drv"
            Case VFT2_DRV_SYSTEM
               FileSubType = "System drv"
            Case VFT2_DRV_INSTALLABLE
               FileSubType = "Installable"
            Case VFT2_DRV_SOUND
               FileSubType = "Sound drv"
            Case VFT2_DRV_COMM
               FileSubType = "Comm drv"
            Case VFT2_UNKNOWN
               FileSubType = "Unknown"
         End Select
      Case VFT_FONT
         FileType = "Font"
         Select Case udtVerBuffer.dwFileSubtype
            Case VFT_FONT_RASTER
               FileSubType = "Raster Font"
            Case VFT_FONT_VECTOR
               FileSubType = "Vector Font"
            Case VFT_FONT_TRUETYPE
               FileSubType = "TrueType Font"
         End Select
      Case VFT_VXD
         FileType = "VxD"
      Case VFT_STATIC_LIB
         FileType = "Lib"
      Case Else
         FileType = "Unknown"
   End Select
   
End Sub

0
 
wormboy__6Author Commented:
i am going to be really annoying and ask you to please simplify that down..so that there is just one function that gets the file version no. of a known file path...

if you wouldnt mind please
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
mcriderCommented:
This microsoft KB article explains how to get the version number of a file...

How to Use Functions in VERSION.DLL -- A 32-bit Sample App
http://support.microsoft.com/support/kb/articles/Q139/4/91.asp 


Cheers!
0
 
cvidlerCommented:
mcrider, thanks that'll come in handy
0
 
mcriderCommented:
Are you going to award the points?


Cheers!
0
 
cvidlerCommented:
I didn't ask the question - just a passer by!!!
0
 
mcriderCommented:
OOPS! So Sorry...


Cheers!
0
All Courses

From novice to tech pro — start learning today.