Retrieving file version 
Author Message
 Retrieving file version

I want to retrieve file information. I have some code written in VB3
and it works fine. Is there anybody out there who can help me
translate this to VB6?

Avi Manor

This is the code in VB3:

Here are some lines that retrieve file information:
   'Debug.Print GetFileVersion((Found_List.Text), "CompanyName")
   'Debug.Print GetFileVersion((Found_List.Text), "FileDescription")
   'Debug.Print GetFileVersion((Found_List.Text), "FileVersion")
   Version_Label.Caption = GetFileVersion(Search_File.Path + "\" +
Search_File.FileName, "ProductName")
   Version_Label.Caption = Version_Label.Caption + " Ver. " +
GetFileVersion(Search_File.Path + "\" + Search_File.FileName,

Here are some API declarations:
Declare Function GetFileVersionInfoSize Lib "ver.dll" (ByVal
lpszFileName As String, lpdwHandle As Long) As Long
Declare Function GetFileVersionInfo Lib "ver.dll" (ByVal lpszFileName
As String, ByVal lpdwHandle As Long, ByVal cbbuf As Long, ByVal
lpvdata As String) As Integer
Declare Function VerQueryValue Lib "ver.dll" (ByVal lpvBlock As
String, ByVal lpszSubBlock As String, lplpBuffer As Long, lpcb As
Integer) As Integer
Declare Function lstrcpyn Lib "Kernel" (ByVal lpszString1 As Any,
ByVal lpszString2 As Long, ByVal cChars As Integer) As Long
Declare Function DiskSpaceFree Lib "SETUPKIT.DLL" () As Long

This function is dowing the dirty work:
Function GetFileVersion (FileToCheck As String, xi_subver As String)
As String

' FileToCheck is the file name and path
' xi_subver indicates the required information

   Dim lpdwHandle&, VersionInfoSize&, lplpBuffer&, stringcopy&,
   Dim lpvdata$, TransString$, fixedstr$, char$, nextchar$,
   Dim VersionInfo%, lpcb%, ptrFixed%, ptrString%
   Dim i As Integer

   On Error Resume Next
   VersionInfoSize& = GetFileVersionInfoSize(FileToCheck, lpdwHandle&)
   If VersionInfoSize& = 0 Then
      GetFileVersion = ""
      Exit Function
   End If
   lpvdata$ = String(VersionInfoSize&, Chr$(0))
   VersionInfo% = GetFileVersionInfo(FileToCheck, lpdwHandle&,
VersionInfoSize&, lpvdata$)
   ptrFixed% = VerQueryValue(lpvdata$, "\FILEVERSION", lplpBuffer&,

   If ptrFixed% = 0 Then
      ' Take a shot with the hardcoded TransString
      TransString$ = "040904E4"
      ptrString% = VerQueryValue(lpvdata$, "\StringFileInfo\" &
TransString$ & "\CompanyName", lplpBuffer&, lpcb%)
      If ptrString% <> 0 Then GoTo GetValues
      ptrFixed% = VerQueryValue(lpvdata$, "\", lplpBuffer&, lpcb%)
      If ptrFixed% = 0 Then
         GetFileVersion = ""
         Exit Function
         TransString$ = ""
         fixedstr$ = String(lpcb% + 1, Chr(0))
         stringcopy& = lstrcpyn(fixedstr$, lplpBuffer&, lpcb% + 1)
         For i = lpcb% To 1 Step -1
            char$ = Hex(Asc(Mid(fixedstr$, i, 1)))
            If Len(char$) = 1 Then
               char$ = "0" + char$
            End If
            TransString$ = TransString$ + char$
            If Len(TransString$ & nextchar$) Mod 8 = 0 Then
               TransString$ = "&H" & TransString$
               TransValue& = Val(TransString$)
               TransString$ = ""
            End If
         Next i
      End If
    End If
    TransTable$ = String(lpcb% + 1, Chr(0))
    TransString$ = String(0, Chr(0))
    stringcopy& = lstrcpyn(TransTable$, lplpBuffer&, lpcb% + 1)
    For i = 1 To lpcb%
      char$ = Hex(Asc(Mid(TransTable$, i, 1)))
      If Len(char$) = 1 Then
         char$ = "0" + char$
      End If
      If Len(TransString$ & nextchar$) Mod 4 = 0 Then
         nextchar$ = char$
         TransString$ = TransString$ + char$ + nextchar$
         nextchar$ = ""
         char$ = ""
      End If
   Next i
   'ptrString% = VerQueryValue(lpvdata$, "\StringFileInfo\" &
TransString$ & "\FileVersion", lplpBuffer&, lpcb%)
   ptrString% = VerQueryValue(lpvdata$, "\StringFileInfo\" &
TransString$ & "\" & xi_subver, lplpBuffer&, lpcb%)
   If ptrString% = 1 Then
      TransTable$ = String(lpcb%, Chr(0))
      stringcopy& = lstrcpyn(TransTable$, lplpBuffer&, lpcb% + 1)
      GetFileVersion = TransTable$
      GetFileVersion = ""
   End If

End Function

Fri, 29 Jul 2005 15:12:43 GMT  
 Retrieving file version

>I want to retrieve file information. I have some code written in VB3
>and it works fine. Is there anybody out there who can help me
>translate this to VB6?

For starters kernel.dll (as user.dll) have been renamed to kernel32
and user32 to reflect the 32 bit environment.
ver.dll is now version.dll
DiskSpaceFree is obsolete i think.. use GetDiskFreeSpace or
Fire up the ApiViewer ffrom the VB Add-Ins to grab the correct
declarations, or visit

Once you fix those you may find it works straight up, but make sure
your variables in use are the same type as required. For example the
16 bit versions used Integers at a lot of places where the 32 bit uses
longs. VB integers are 16 bit even in a 32 bit environment, so as you
can imagine things will start to melt if you leave them that way.

Hope this gets it done.. if not, yell again, me or others may have
some more ideas.. We always do. :-)


Regards, Frank

Fri, 29 Jul 2005 15:27:04 GMT  
 [ 2 post ] 

 Relevant Pages 

1. Retrieving File Version information in VB

2. retrieving file version

3. Error retrieving file version information using "VerQueryValue"

4. Retrieving the version number from a file

5. Retrieving a DLL's version from code

6. API to retrieve O/S version

7. How do I retrieve the application version?

8. How would I retrieve IE Browser version?

9. how to retrieve version from EXE [Q]

10. Retrieving Bios version from computers in a windows 2000 domain

11. Retrieve version of ADO

12. Retrieve version of ADO


Powered by phpBB® Forum Software