Results 1 to 13 of 13

Thread: Getting File Version...

  1. #1

    Thread Starter
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    Getting File Version...

    How do you get the version of a DLL or EXE on your PC?
    I have seen code where you have to downlaod a DLL from a web site. This DLL contains some API that deals with getting the file info.

    Do I have to do this?

    There must be an easier way....???

    Woof

  2. #2
    Fanatic Member wildcat_2000's Avatar
    Join Date
    Nov 2000
    Location
    Italy
    Posts
    727
    i use this, works pretty well...
    When your car breaks down,
    close all windows and retry

    => please rate all users posts! <=

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    How's this?
    VB Code:
    1. Const VS_FFI_SIGNATURE = &HFEEF04BD
    2. Const VS_FFI_STRUCVERSION = &H10000
    3. Const VS_FFI_FILEFLAGSMASK = &H3F&
    4. Const VS_FF_DEBUG = &H1
    5. Const VS_FF_PRERELEASE = &H2
    6. Const VS_FF_PATCHED = &H4
    7. Const VS_FF_PRIVATEBUILD = &H8
    8. Const VS_FF_INFOINFERRED = &H10
    9. Const VS_FF_SPECIALBUILD = &H20
    10. Const VOS_UNKNOWN = &H0
    11. Const VOS_DOS = &H10000
    12. Const VOS_OS216 = &H20000
    13. Const VOS_OS232 = &H30000
    14. Const VOS_NT = &H40000
    15. Const VOS__BASE = &H0
    16. Const VOS__WINDOWS16 = &H1
    17. Const VOS__PM16 = &H2
    18. Const VOS__PM32 = &H3
    19. Const VOS__WINDOWS32 = &H4
    20. Const VOS_DOS_WINDOWS16 = &H10001
    21. Const VOS_DOS_WINDOWS32 = &H10004
    22. Const VOS_OS216_PM16 = &H20002
    23. Const VOS_OS232_PM32 = &H30003
    24. Const VOS_NT_WINDOWS32 = &H40004
    25. Const VFT_UNKNOWN = &H0
    26. Const VFT_APP = &H1
    27. Const VFT_DLL = &H2
    28. Const VFT_DRV = &H3
    29. Const VFT_FONT = &H4
    30. Const VFT_VXD = &H5
    31. Const VFT_STATIC_LIB = &H7
    32. Const VFT2_UNKNOWN = &H0
    33. Const VFT2_DRV_PRINTER = &H1
    34. Const VFT2_DRV_KEYBOARD = &H2
    35. Const VFT2_DRV_LANGUAGE = &H3
    36. Const VFT2_DRV_DISPLAY = &H4
    37. Const VFT2_DRV_MOUSE = &H5
    38. Const VFT2_DRV_NETWORK = &H6
    39. Const VFT2_DRV_SYSTEM = &H7
    40. Const VFT2_DRV_INSTALLABLE = &H8
    41. Const VFT2_DRV_SOUND = &H9
    42. Const VFT2_DRV_COMM = &HA
    43. Private Type VS_FIXEDFILEINFO
    44.    dwSignature As Long
    45.    dwStrucVersionl As Integer     '  e.g. = &h0000 = 0
    46.    dwStrucVersionh As Integer     '  e.g. = &h0042 = .42
    47.    dwFileVersionMSl As Integer    '  e.g. = &h0003 = 3
    48.    dwFileVersionMSh As Integer    '  e.g. = &h0075 = .75
    49.    dwFileVersionLSl As Integer    '  e.g. = &h0000 = 0
    50.    dwFileVersionLSh As Integer    '  e.g. = &h0031 = .31
    51.    dwProductVersionMSl As Integer '  e.g. = &h0003 = 3
    52.    dwProductVersionMSh As Integer '  e.g. = &h0010 = .1
    53.    dwProductVersionLSl As Integer '  e.g. = &h0000 = 0
    54.    dwProductVersionLSh As Integer '  e.g. = &h0031 = .31
    55.    dwFileFlagsMask As Long        '  = &h3F for version "0.42"
    56.    dwFileFlags As Long            '  e.g. VFF_DEBUG Or VFF_PRERELEASE
    57.    dwFileOS As Long               '  e.g. VOS_DOS_WINDOWS16
    58.    dwFileType As Long             '  e.g. VFT_DRIVER
    59.    dwFileSubtype As Long          '  e.g. VFT2_DRV_KEYBOARD
    60.    dwFileDateMS As Long           '  e.g. 0
    61.    dwFileDateLS As Long           '  e.g. 0
    62. End Type
    63. 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
    64. Private Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
    65. Private Declare Function VerQueryValue Lib "Version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, puLen As Long) As Long
    66. Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, ByVal Source As Long, ByVal length As Long)
    67. Dim Filename As String, Directory As String, FullFileName As String
    68. Dim StrucVer As String, FileVer As String, ProdVer As String
    69. Dim FileFlags As String, FileOS As String, FileType As String, FileSubType As String
    70. Private Sub DisplayVerInfo()
    71.    Dim rc As Long, lDummy As Long, sBuffer() As Byte
    72.    Dim lBufferLen As Long, lVerPointer As Long, udtVerBuffer As VS_FIXEDFILEINFO
    73.    Dim lVerbufferLen As Long
    74.  
    75.    '*** Get size ****
    76.    lBufferLen = GetFileVersionInfoSize(FullFileName, lDummy)
    77.    If lBufferLen < 1 Then
    78.       MsgBox "No Version Info available!"
    79.       Exit Sub
    80.    End If
    81.  
    82.    '**** Store info to udtVerBuffer struct ****
    83.    ReDim sBuffer(lBufferLen)
    84.    rc = GetFileVersionInfo(FullFileName, 0&, lBufferLen, sBuffer(0))
    85.    rc = VerQueryValue(sBuffer(0), "\", lVerPointer, lVerbufferLen)
    86.    MoveMemory udtVerBuffer, lVerPointer, Len(udtVerBuffer)
    87.  
    88.    '**** Determine Structure Version number - NOT USED ****
    89.    StrucVer = Format$(udtVerBuffer.dwStrucVersionh) & "." & Format$(udtVerBuffer.dwStrucVersionl)
    90.  
    91.    '**** Determine File Version number ****
    92.    FileVer = Format$(udtVerBuffer.dwFileVersionMSh) & "." & Format$(udtVerBuffer.dwFileVersionMSl) & "." & Format$(udtVerBuffer.dwFileVersionLSh) & "." & Format$(udtVerBuffer.dwFileVersionLSl)
    93.  
    94.    '**** Determine Product Version number ****
    95.    ProdVer = Format$(udtVerBuffer.dwProductVersionMSh) & "." & Format$(udtVerBuffer.dwProductVersionMSl) & "." & Format$(udtVerBuffer.dwProductVersionLSh) & "." & Format$(udtVerBuffer.dwProductVersionLSl)
    96.  
    97.    '**** Determine Boolean attributes of File ****
    98.    FileFlags = ""
    99.    If udtVerBuffer.dwFileFlags And VS_FF_DEBUG Then FileFlags = "Debug "
    100.    If udtVerBuffer.dwFileFlags And VS_FF_PRERELEASE Then FileFlags = FileFlags & "PreRel "
    101.    If udtVerBuffer.dwFileFlags And VS_FF_PATCHED Then FileFlags = FileFlags & "Patched "
    102.    If udtVerBuffer.dwFileFlags And VS_FF_PRIVATEBUILD Then FileFlags = FileFlags & "Private "
    103.    If udtVerBuffer.dwFileFlags And VS_FF_INFOINFERRE Then FileFlags = FileFlags & "Info "
    104.    If udtVerBuffer.dwFileFlags And VS_FF_SPECIALBUILD Then FileFlags = FileFlags & "Special "
    105.    If udtVerBuffer.dwFileFlags And VFT2_UNKNOWN Then FileFlags = FileFlags + "Unknown "
    106.  
    107.    '**** Determine OS for which file was designed ****
    108.    Select Case udtVerBuffer.dwFileOS
    109.       Case VOS_DOS_WINDOWS16
    110.         FileOS = "DOS-Win16"
    111.       Case VOS_DOS_WINDOWS32
    112.         FileOS = "DOS-Win32"
    113.       Case VOS_OS216_PM16
    114.         FileOS = "OS/2-16 PM-16"
    115.       Case VOS_OS232_PM32
    116.         FileOS = "OS/2-16 PM-32"
    117.       Case VOS_NT_WINDOWS32
    118.         FileOS = "NT-Win32"
    119.       Case other
    120.         FileOS = "Unknown"
    121.    End Select
    122.    Select Case udtVerBuffer.dwFileType
    123.       Case VFT_APP
    124.          FileType = "App"
    125.       Case VFT_DLL
    126.          FileType = "DLL"
    127.       Case VFT_DRV
    128.          FileType = "Driver"
    129.          Select Case udtVerBuffer.dwFileSubtype
    130.             Case VFT2_DRV_PRINTER
    131.                FileSubType = "Printer drv"
    132.             Case VFT2_DRV_KEYBOARD
    133.                FileSubType = "Keyboard drv"
    134.             Case VFT2_DRV_LANGUAGE
    135.                FileSubType = "Language drv"
    136.             Case VFT2_DRV_DISPLAY
    137.                FileSubType = "Display drv"
    138.             Case VFT2_DRV_MOUSE
    139.                FileSubType = "Mouse drv"
    140.             Case VFT2_DRV_NETWORK
    141.                FileSubType = "Network drv"
    142.             Case VFT2_DRV_SYSTEM
    143.                FileSubType = "System drv"
    144.             Case VFT2_DRV_INSTALLABLE
    145.                FileSubType = "Installable"
    146.             Case VFT2_DRV_SOUND
    147.                FileSubType = "Sound drv"
    148.             Case VFT2_DRV_COMM
    149.                FileSubType = "Comm drv"
    150.             Case VFT2_UNKNOWN
    151.                FileSubType = "Unknown"
    152.          End Select
    153.       Case VFT_FONT
    154.          FileType = "Font"
    155.          Select Case udtVerBuffer.dwFileSubtype
    156.             Case VFT_FONT_RASTER
    157.                FileSubType = "Raster Font"
    158.             Case VFT_FONT_VECTOR
    159.                FileSubType = "Vector Font"
    160.             Case VFT_FONT_TRUETYPE
    161.                FileSubType = "TrueType Font"
    162.          End Select
    163.       Case VFT_VXD
    164.          FileType = "VxD"
    165.       Case VFT_STATIC_LIB
    166.          FileType = "Lib"
    167.       Case Else
    168.          FileType = "Unknown"
    169.    End Select
    170. End Sub
    171. Private Sub Form_Load()
    172.     'KPD-Team 2000
    173.     'URL: [url]http://www.allapi.net/[/url]
    174.     'E-Mail: [email][email protected][/email]
    175.     'Source -> MS Knowledge Base
    176.     'set the file
    177.     Filename = "kernel32.dll"
    178.     Directory = "c:\windows\system\"
    179.     FullFileName = Directory + Filename
    180.     'set graphics mode to persistent
    181.     Me.AutoRedraw = True
    182.     'retrieve the information
    183.     DisplayVerInfo
    184.     'show the results
    185.     Me.Print "Full filename: " + FullFileName
    186.     Me.Print "File version: " + FileVer
    187.     Me.Print "Product version: " + ProdVer
    188.     Me.Print "File flags: " + FileFlags
    189.     Me.Print "File OS: " + FileOS
    190.     Me.Print "File type: " + FileType + IIf(FileSubType = "", "", " (" + FileSubType + ")")
    191. End Sub

  4. #4

  5. #5
    Fanatic Member wildcat_2000's Avatar
    Join Date
    Nov 2000
    Location
    Italy
    Posts
    727
    Originally posted by Wokawidget

    What's the difference between product version and file versions?
    just a way for programmers to differentiate the file version from a product version
    When your car breaks down,
    close all windows and retry

    => please rate all users posts! <=

  6. #6

  7. #7
    Fanatic Member wildcat_2000's Avatar
    Join Date
    Nov 2000
    Location
    Italy
    Posts
    727
    often.

    don't get stuck on this it's just a way to allow multiple file version for a same product version (ex: product v2.1.10 file versions 2.1.10 for winNT and 2.1.11 for win98)...
    When your car breaks down,
    close all windows and retry

    => please rate all users posts! <=

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    Yep, I've seen some MS programs with a product (or was it file?) version being the same as the Windows version number.

    Having different product versions on each may or may not mean that they are different in some way... but I haven't got multiple copies of files to test it with!

  9. #9
    Lively Member
    Join Date
    Jun 2004
    Posts
    74
    Why not just use the FileSystemObject to get what you need?

  10. #10

  11. #11
    Lively Member
    Join Date
    Jun 2004
    Posts
    74
    Yes. There is a GetFileVersion method for a File type under the FSO...

    Example to List the File and Version for all files in WINDOWS/SYSTEM32 dir...

    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Dim fle As Object
    Set fle = CreateObject("Scripting.FileSystemObject.File")

    Dim s As String

    For Each fle In fso.GetFolder("c:\winnt\system32").Files

    s = s & fle & vbTab & fso.GetFileVersion(fle) & vbCrLf

    Next
    Debug.Print s

    Good Luck,

    Hume

  12. #12

  13. #13
    Lively Member
    Join Date
    Jun 2004
    Posts
    74
    Glad to help. There was a really good white paper put out by the Mandelbrot Set, "Using the File System Object and some other 'Scripting Stuff') in Visual Basic", on using the File System Object. Do a Google hit and take a look. Opened my eyes to some things I never knew about...

    Later

    Hume

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width