CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Guest

    File Version Information

    Does any one know how to get a files version information using the Windows API. I already know how to use the GetFileVersionInfo to get a files version number. But what I'm really interested in is getting a files advanced version information such as 'Product Name', 'Internal Name' and 'Company Name'. Any examples would be helpful.


  2. #2
    Join Date
    Sep 1999
    Location
    Red Wing, MN USA
    Posts
    312

    Re: File Version Information

    Here, try this, it extracts all the File Information, (Works only on 32-bit Files):

    Add a Textbox, CommandButton and CommonDialogbox to a Form..
    Code:
    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 Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (lpString1 as Any, lpString2 as Any) as Long
    
    private Sub Command1_Click()
        Dim sVerInfo(7) as string
        Dim sInfo as string
        Dim sValue as string
        Dim sFile as string
        Dim sData() as Byte
        Dim lSize as Long
        Dim lPointer as Long
        Dim iIndex as Integer
         
        on error GoTo OpenError
        With CommonDialog1
            .CancelError = true
            .ShowOpen
            sFile = .FileName
        End With
        Text1 = ""
        'get the Length of the FileVersion Information
        lSize = GetFileVersionInfoSize(sFile, byval 0&)
        'Create a Buffer to hold the Version Info
        ReDim sData(lSize)
        'get the Version Info
        If GetFileVersionInfo(sFile, 0&, lSize, sData(0)) then
            'Extract the Details of the Version Info
            sVerInfo(0) = "CompanyName"
            sVerInfo(1) = "FileDescription"
            sVerInfo(2) = "FileVersion"
            sVerInfo(3) = "InternalName"
            sVerInfo(4) = "LegalCopyright"
            sVerInfo(5) = "OriginalFileName"
            sVerInfo(6) = "ProductName"
            sVerInfo(7) = "ProductVersion"
            for iIndex = 0 to 7
                sInfo = "\StringFileInfo\040904E4\" & sVerInfo(iIndex)
                If VerQueryValue(sData(0), sInfo, lPointer, lSize) then
                    sValue = Space(lSize)
                    lstrcpy byval sValue, byval lPointer
                    Text1.SelText = sVerInfo(iIndex) & ": " & sValue
                    Text1.SelText = vbCrLf
                End If
             next
        End If
    OpenError:
    End Sub

    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Last edited by Cimperiali; March 23rd, 2004 at 05:16 AM.
    Aaron Young
    Senior Programmer Analyst (Red Wing Software)
    Certified AllExperts Expert

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

Featured