Results 1 to 3 of 3

Thread: [resolved] Can't read file information

  1. #1

    Thread Starter
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Ontario, Canada

    Unhappy [resolved] Can't read file information

    I'm looking for a way to read the file version information. I have done a dozen searches and have found nothing to do this.

    For example, right click on an EXE, and select Properties. Switch to the Version tab. You will see three values at the very top:

    File Version

    I want to read these values from an EXE. Does anyone have any idea on how to do this? I haven't been able to locate any code that does this.

    Of course,... this is super easy to do in .NET, but i need a way to do it in VB6.
    Last edited by MrGTI; Apr 18th, 2006 at 01:59 PM. Reason: resolved

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Searching for mendhak

    Re: Can't read file information

    I saved the link to where I found this, but that link doesn't work anymore so I'm glad I saved the code to. See if this does anything for you.
    VB Code:
    1. Option Explicit
    3. Private Declare Function GetFileVersionInfo Lib "Version.dll" Alias _
    4. "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwHandle As Long, _
    5. ByVal dwLen As Long, lpData As Any) As Long
    7. Private Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias _
    8. "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
    10. Private Declare Function VerQueryValue Lib "Version.dll" Alias _
    11. "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, _
    12. puLen As Long) As Long
    14. Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (lpString1 As Any, _
    15. lpString2 As Any) As Long
    17. Private Sub Command1_Click()
    18.     Dim sVerInfo(7) As String
    19.     Dim sInfo As String
    20.     Dim sValue As String
    21.     Dim sFile As String
    22.     Dim sData() As Byte
    23.     Dim lSize As Long
    24.     Dim lPointer As Long
    25.     Dim iIndex As Integer
    27.     On Error GoTo OpenError
    28.     With CommonDialog1
    29.         .CancelError = True
    30.         .ShowOpen
    31.         sFile = .FileName
    32.     End With
    33.     Text1 = ""
    34.     'get the Length of the FileVersion Information
    35.     lSize = GetFileVersionInfoSize(sFile, ByVal 0&)
    36.     'Create a Buffer to hold the Version Info
    37.     ReDim sData(lSize)
    38.     'get the Version Info
    39.     If GetFileVersionInfo(sFile, 0&, lSize, sData(0)) Then
    40.         'Extract the Details of the Version Info
    41.         sVerInfo(0) = "CompanyName"
    42.         sVerInfo(1) = "FileDescription"
    43.         sVerInfo(2) = "FileVersion"
    44.         sVerInfo(3) = "InternalName"
    45.         sVerInfo(4) = "LegalCopyright"
    46.         sVerInfo(5) = "OriginalFileName"
    47.         sVerInfo(6) = "ProductName"
    48.         sVerInfo(7) = "ProductVersion"
    49.         For iIndex = 0 To 7
    50.             sInfo = "\StringFileInfo\040904E4\" & sVerInfo(iIndex)
    51.             If VerQueryValue(sData(0), sInfo, lPointer, lSize) Then
    52.                 sValue = Space(lSize)
    53.                 lstrcpy ByVal sValue, ByVal lPointer
    54.                 Text1.SelText = sVerInfo(iIndex) & ": " & sValue
    55.                 Text1.SelText = vbCrLf
    56.             End If
    57.          Next
    58.     End If
    59. OpenError:
    60. End Sub

  3. #3

    Thread Starter
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Ontario, Canada

    Thumbs up

    I'm glad you saved the code, because it worked. Very good code. Thanks.

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