Results 1 to 3 of 3

Thread: Getting DLL File Version

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    New York City
    Posts
    73

    I'm trying to populate a list box with DLL names and version numbers but I can't figure out how to get the version number in code. You can get most info with Filesystemobject but not version

    Any help would be greatly appreciated!
    Rich

  2. #2
    Guest
    This will get a file's version:

    Code:
    'Submitted by: Riaan Aspeling
    'Origin: http://www.planet-source-code.com
    'Purpose: Retrieve the version of a file (EXE/DLL etc).
    'Version: VB4+ 
    
    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 MoveMemory Lib "kernel32" _
    Alias "RtlMoveMemory" (dest As Any, ByVal Source As Long, _
    ByVal Length As Long)
    
    
    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 Function CheckFileVersion(FilenameAndPath As Variant) As Variant
        On Error Goto HandelCheckFileVersionError
        Dim lDummy As Long, lsize As Long, rc As Long
        Dim lVerbufferLen As Long, lVerPointer As Long
        Dim sBuffer() As Byte
        Dim udtVerBuffer As VS_FIXEDFILEINFO
        Dim ProdVer As String
        lsize = GetFileVersionInfoSize(FilenameAndPath, lDummy)
        If lsize < 1 Then Exit Function
        ReDim sBuffer(lsize)
        rc = GetFileVersionInfo(FilenameAndPath, 0&, lsize, sBuffer(0))
        rc = VerQueryValue(sBuffer(0), "\", lVerPointer, lVerbufferLen)
        MoveMemory udtVerBuffer, lVerPointer, Len(udtVerBuffer)
        '**** Determine Product Version number *
        '     ***
        ProdVer = Format$(udtVerBuffer.dwProductVersionMSh) & "." & Format$(udtVerBuffer.dwProductVersionMSl)
        CheckFileVersion = ProdVer
        Exit Function
        HandelCheckFileVersionError:
        CheckFileVersion = "N/A"
        Exit Function
    End Function

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2000
    Location
    New York City
    Posts
    73
    Matthew,

    Thanks a lot!! Worked out great!

    Just FYI, the function returns an abbreviated version number. If you want to get the full version number replace this line in the function:

    ProdVer = Format$(udtVerBuffer.dwProductVersionMSh) & "." & Format$(udtVerBuffer.dwProductVersionMSl)

    with this one:

    ProdVer = Format$(udtVerBuffer.dwProductVersionMSh) & "." & Format$(udtVerBuffer.dwProductVersionMSl) & "." & Format$(udtVerBuffer.dwFileVersionLSh) & Format$(udtVerBuffer.dwFileVersionLSl)
    Rich

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