Results 1 to 10 of 10

Thread: Get version problem

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    Egypt
    Posts
    162

    Smile Get version problem

    Hi everybody

    I guess that this is the right forum , to ask about this :

    I want to get version for a file so I use this :

    VB Code:
    1. Private Type VS_FIXEDFILEINFO
    2.    dwSignature As Long
    3.    dwStrucVersionl As Integer
    4.    dwStrucVersionh As Integer
    5.    dwFileVersionMSl As Integer
    6.    dwFileVersionMSh As Integer
    7.    dwFileVersionLSl As Integer
    8.    dwFileVersionLSh As Integer
    9.    dwProductVersionMSl As Integer
    10.    dwProductVersionMSh As Integer
    11.    dwProductVersionLSl As Integer
    12.    dwProductVersionLSh As Integer
    13.    dwFileFlagsMask As Long
    14.    dwFileFlags As Long
    15.    dwFileOS As Long
    16.    dwFileType As Long
    17.    dwFileSubtype As Long
    18.    dwFileDateMS As Long
    19.    dwFileDateLS As Long
    20. End Type
    21.  
    22.  
    23. 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
    24. Private Declare Function GetFileVersionInfoSize Lib "Version.dll" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
    25. Private Declare Function VerQueryValue Lib "Version.dll" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Any, puLen As Long) As Long
    26. Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, ByVal Source As Long, ByVal length As Long)
    27.  
    28.  
    29. Public Function GetFileVersion(FilePath As String) As String
    30. Dim Rc As Long, lDummy As Long, sBuffer() As Byte
    31. Dim lBufferLen As Long, lVerPointer As Long, udtVerBuffer As VS_FIXEDFILEINFO
    32. Dim lVerbufferLen As Long
    33.  
    34. lBufferLen = GetFileVersionInfoSize(FilePath, lDummy)
    35.  
    36. If lBufferLen < 1 Then
    37.     GetFileVersion = "0"
    38.    'GetFileVersion = "No Version Info available"
    39.    'Err.Raise 1000, , "No Version Info available"
    40.    Exit Function
    41. End If
    42.  
    43. ReDim sBuffer(lBufferLen)
    44. Rc = GetFileVersionInfo(FilePath, 0&, lBufferLen, sBuffer(0))
    45. Rc = VerQueryValue(sBuffer(0), "\", lVerPointer, lVerbufferLen)
    46. MoveMemory udtVerBuffer, lVerPointer, Len(udtVerBuffer)
    47.  
    48.  
    49. GetFileVersion = Format$(udtVerBuffer.dwFileVersionMSh) & "." & Format$(udtVerBuffer.dwFileVersionMSl) & "." & Format$(udtVerBuffer.dwFileVersionLSh) & "." & Format$(udtVerBuffer.dwFileVersionLSl)
    50.  
    51. End Function

    Windows properties show this :


    Using the APIs method I get this (2.0.-14809.42)

    The question is what my method needs to get that number surrounded by the first red elliptical mark (in the image).

    Thanks
    Mohammed Sayed - Egypt - Anesthetist



    =

    =

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    Egypt
    Posts
    162

    Re: Get version problem

    Was it the wrong forum ???
    Mohammed Sayed - Egypt - Anesthetist



    =

    =

  3. #3
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Get version problem

    Where is the Red Mark?

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    Egypt
    Posts
    162

    Re: Get version problem

    the first red elliptical mark
    the first one around (2.0.50727.42)
    Last edited by msayed2004; Oct 30th, 2006 at 11:06 PM.
    Mohammed Sayed - Egypt - Anesthetist



    =

    =

  5. #5
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Get version problem

    Do you mean 2?

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    Egypt
    Posts
    162

    Re: Get version problem

    No number 1 , this [2.0.50727.42] not this [2.0.50727.42(RTM.050727-4200)]
    Mohammed Sayed - Egypt - Anesthetist



    =

    =

  7. #7
    Learning .Net danasegarane's Avatar
    Join Date
    Aug 2004
    Location
    VBForums
    Posts
    5,853

    Re: Get version problem

    What File your are using for this particular Problem

  8. #8
    Member
    Join Date
    Oct 2006
    Posts
    53

    Re: Get version problem

    There are 12 predefined version information strings. You get all information in one buffer. This is how you retrieve a file version info from the resource.

    1. Get the needed size in bytes with GetFileVersionInfoSize.
    VB Code:
    1. nbytes = GetFileVersionInfoSize(filename, lpdwHandle)

    2. Allocate memory. You can use a byte array and redim it. But then you must use undocumented pointers. Better to use API HeapAlloc. First get the handle to the process heap and then allocate memory. Result is a pointer to memory.
    VB Code:
    1. hHeap = GetProcessHeap
    2. pMem = HeapAlloc(hHeap, 0, nbytes)

    3. Now you can retrieve version information and put it at pMem.
    VB Code:
    1. GetFileVersionInfo filename, 0, nbytes, ByVal pMem

    4. Next you must read the language and codepage.
    VB Code:
    1. VerQueryValue ByVal pMem, "\VarFileInfo\Translation", pLang, dwChar

    5. Now you must put language and codepage together to a string with hex numbers like "040904B0". To proceed you now have a string like "\StringFileInfo\040904B0\".

    6. After that string you add the name of the specific information like this "\StringFileInfo\040904B0\FileVersion".

    7. With API VerQueryValue you can read fileversion info. With the API you get the pointer in allocated memory where the information is hold.
    VB Code:
    1. VerQueryValue ByVal pMem, lpSubBlock & sInfo(i), InfoOut, dwChar

    8. It is VB so you must copy the info to a buffer to make it readable.
    VB Code:
    1. CopyMemory ByVal buffer, ByVal InfoOut, dwChar

    It is rather complicated to read version info so I tryed to explain it in detail. Now you only have to put it together to make it work. If you want all 12 info you can declare a string array
    VB Code:
    1. Dim sInfo(11) as string
    and read all whith a loop. You see sInfo(i) above.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Jun 2006
    Location
    Egypt
    Posts
    162

    Re: Get version problem

    Thanks for reply , I will try this
    Mohammed Sayed - Egypt - Anesthetist



    =

    =

  10. #10
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Get version problem

    here's a lo-tech version:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Debug.Print GetFileInfo("C:\WINDOWS\system32\comctl32.dll", "FileVersion")
    3. End Sub
    4.  
    5. Private Function GetFileInfo(ByVal sFile As String, ByVal sInfo As String) As String
    6.     Dim sData As String, sFind As String, lPos As Long
    7.    
    8.     sFind = StrConv(sInfo, vbUnicode)
    9.     Open sFile For Binary As #1
    10.         sData = Space$(LOF(1))
    11.         Get #1, , sData
    12.     Close #1
    13.    
    14.     lPos = InStr(sData, sFind) + Len(sFind)
    15.     Do While Mid$(sData, lPos, 1) = vbNullChar
    16.         lPos = lPos + 1
    17.     Loop
    18.     sData = StrConv(Mid$(sData, lPos, 100), vbFromUnicode)
    19.    
    20.     GetFileInfo = Left$(sData, InStr(sData, vbNullChar) - 1)
    21. End Function

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