|
-
Oct 30th, 2006, 09:00 AM
#1
Thread Starter
Addicted Member
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:
Private Type VS_FIXEDFILEINFO
dwSignature As Long
dwStrucVersionl As Integer
dwStrucVersionh As Integer
dwFileVersionMSl As Integer
dwFileVersionMSh As Integer
dwFileVersionLSl As Integer
dwFileVersionLSh As Integer
dwProductVersionMSl As Integer
dwProductVersionMSh As Integer
dwProductVersionLSl As Integer
dwProductVersionLSh As Integer
dwFileFlagsMask As Long
dwFileFlags As Long
dwFileOS As Long
dwFileType As Long
dwFileSubtype As Long
dwFileDateMS As Long
dwFileDateLS As Long
End Type
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)
Public Function GetFileVersion(FilePath As String) As String
Dim Rc As Long, lDummy As Long, sBuffer() As Byte
Dim lBufferLen As Long, lVerPointer As Long, udtVerBuffer As VS_FIXEDFILEINFO
Dim lVerbufferLen As Long
lBufferLen = GetFileVersionInfoSize(FilePath, lDummy)
If lBufferLen < 1 Then
GetFileVersion = "0"
'GetFileVersion = "No Version Info available"
'Err.Raise 1000, , "No Version Info available"
Exit Function
End If
ReDim sBuffer(lBufferLen)
Rc = GetFileVersionInfo(FilePath, 0&, lBufferLen, sBuffer(0))
Rc = VerQueryValue(sBuffer(0), "\", lVerPointer, lVerbufferLen)
MoveMemory udtVerBuffer, lVerPointer, Len(udtVerBuffer)
GetFileVersion = Format$(udtVerBuffer.dwFileVersionMSh) & "." & Format$(udtVerBuffer.dwFileVersionMSl) & "." & Format$(udtVerBuffer.dwFileVersionLSh) & "." & Format$(udtVerBuffer.dwFileVersionLSl)
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
-
Oct 30th, 2006, 06:06 PM
#2
Thread Starter
Addicted Member
Re: Get version problem
Was it the wrong forum ???
-
Oct 30th, 2006, 10:48 PM
#3
-
Oct 30th, 2006, 10:54 PM
#4
Thread Starter
Addicted Member
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.
-
Oct 30th, 2006, 11:00 PM
#5
-
Oct 30th, 2006, 11:05 PM
#6
Thread Starter
Addicted Member
Re: Get version problem
No number 1 , this [2.0.50727.42] not this [2.0.50727.42(RTM.050727-4200)]
-
Oct 30th, 2006, 11:22 PM
#7
Re: Get version problem
What File your are using for this particular Problem
-
Oct 31st, 2006, 07:01 AM
#8
Member
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:
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:
hHeap = GetProcessHeap
pMem = HeapAlloc(hHeap, 0, nbytes)
3. Now you can retrieve version information and put it at pMem.
VB Code:
GetFileVersionInfo filename, 0, nbytes, ByVal pMem
4. Next you must read the language and codepage.
VB Code:
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:
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:
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 and read all whith a loop. You see sInfo(i) above.
-
Oct 31st, 2006, 07:44 AM
#9
Thread Starter
Addicted Member
Re: Get version problem
Thanks for reply , I will try this
-
Oct 31st, 2006, 11:12 AM
#10
Re: Get version problem
here's a lo-tech version:
VB Code:
Private Sub Command1_Click()
Debug.Print GetFileInfo("C:\WINDOWS\system32\comctl32.dll", "FileVersion")
End Sub
Private Function GetFileInfo(ByVal sFile As String, ByVal sInfo As String) As String
Dim sData As String, sFind As String, lPos As Long
sFind = StrConv(sInfo, vbUnicode)
Open sFile For Binary As #1
sData = Space$(LOF(1))
Get #1, , sData
Close #1
lPos = InStr(sData, sFind) + Len(sFind)
Do While Mid$(sData, lPos, 1) = vbNullChar
lPos = lPos + 1
Loop
sData = StrConv(Mid$(sData, lPos, 100), vbFromUnicode)
GetFileInfo = Left$(sData, InStr(sData, vbNullChar) - 1)
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|