Results 1 to 3 of 3

Thread: How do I get the file version?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Vaxjo, Sweden
    Posts
    85

    Question

    How do I get the version of an spcified EXE or DLL?

    //Anders

  2. #2
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670
    Try this;

    Code:
    Private Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
    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 VerQueryValue Lib "Version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, nVerSize As Long) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    
    Private Type VS_FIXEDFILEINFO
       dwSignature As Long
       dwStrucVersion As Long         
       dwFileVersionMS As Long
       dwFileVersionLS As Long
       dwProductVersionMS As Long
       dwProductVersionLS As Long
       dwFileFlagsMask As Long
       dwFileFlags As Long
       dwFileOS As Long
       dwFileType As Long
       dwFileSubtype As Long
       dwFileDateMS As Long
       dwFileDateLS As Long
    End Type
    
    Function GetFileVersion(sFileName As String) As String
    Dim FI As VS_FIXEDFILEINFO
    Dim sBuffer() As Byte
    Dim nBufferSize As Long
    Dim lpBuffer As Long
    Dim nVerSize As Long
    Dim nUnused As Long
    Dim tmpVer As String
    nBufferSize = GetFileVersionInfoSize(sFileName, nUnused)
    If nBufferSize > 0 Then
        ReDim sBuffer(nBufferSize)
        Call GetFileVersionInfo(sFileName, 0&, nBufferSize, sBuffer(0))
        Call VerQueryValue(sBuffer(0), "\", lpBuffer, nVerSize)
        Call CopyMemory(FI, ByVal lpBuffer, Len(FI))
        tmpVer = Format$(HiWord(FI.dwFileVersionMS)) & "." & Format$(LoWord(FI.dwFileVersionMS), "0")
        If FI.dwFileVersionLS > 0 Then
            tmpVer = tmpVer & "." & Format$(FI.dwFileVersionLS, "000")
        End If
    End If
    GetFileVersion = tmpVer
    End Function
    
    Private Function HiWord(dw As Long) As Long
    If (dw And &H80000000) Then HiWord = ((dw \ 65535) - 1) Else HiWord = (dw \ 65535)
    End Function
    
    Private Function LoWord(dw As Long) As Long
    If (dw And &H8000&) Then LoWord = (&H8000 Or (dw And &H7FFF&)) Else LoWord = (dw And &HFFFF&)
    End Function
    This will return a string of the file version... eg 1.2.002

    'Buzby'
    Visual Basic Developer
    "I'm moving to Theory. Everything works there."

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2000
    Location
    Vaxjo, Sweden
    Posts
    85
    Lovely, just what I need!

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