file version!!! 
Author Message
 file version!!!

Hi,

The following code allows to get the version information on a specific
file. It works only if you place the file in ..\system32 directory:
If I change the code as follows:
FullFileName = "c:\test\myprogram.exe" it down't work

Please help and ccmail me just in case I miss your email in the
newsgroup.

Thanks

afh

Private Sub Command1_Click()
   Dim Buffer As String
   Dim rc As Long
   Dim FullFileName As String

   '*** We will check the FileDescription of the gdi32.dll****
   Buffer = String(255, 0)
   rc = GetSystemDirectory(Buffer, Len(Buffer))
   Buffer = LCase$(Mid$(Buffer, 1, InStr(Buffer, Chr(0)) - 1))
   FullFileName = Buffer & "\gdi32.dll"
   FullFileName = "c:\predator\rel.2_1\pblotter.exe"
   Dim lBufferLen As Long, lDummy As Long
   '*** Get size ****
   lBufferLen = GetFileVersionInfoSize(FullFileName, lDummy)
   If lBufferLen < 1 Then
      MsgBox "No Version Info available!"
      Exit Sub
   End If

   Dim sBuffer()  As Byte
   ReDim sBuffer(lBufferLen)
   rc = GetFileVersionInfo(FullFileName, 0&, lBufferLen, _
        sBuffer(0))
   If rc = 0 Then
      MsgBox "GetFileVersionInfo failed."
      Exit Sub
   End If

   Dim lVerPointer As Long

   rc = VerQueryValue(sBuffer(0), "\VarFileInfo\Translation", _
        lVerPointer, lBufferLen)
   If rc = 0 Then
      MsgBox "VerQueryValue failed."
      Exit Sub
   End If
   'lVerPointer is a pointer to four 4 bytes of Hex number,
   'first two bytes are language id, and last two bytes are code
   'page. However, Lang_Charset_String needs a  string of
   '4 hex digits, the first two characters correspond to the
   'language id and last two the last two character correspond
   'to the code page id.

   Dim bytebuffer(255) As Byte
   MoveMemory bytebuffer(0), lVerPointer, lBufferLen
   Dim Lang_Charset_String As String
   Dim HexNumber As Long

    HexNumber = bytebuffer(2) + bytebuffer(3) * &H100 + _
        bytebuffer(0) * &H10000 + bytebuffer(1) * &H1000000
    Lang_Charset_String = Hex(HexNumber)
    'now we change the order of the language id and code page
    'and convert it into a string representation.
    'For example, it may look like 040904E4
    'Or to pull it all apart:
    '04------        = SUBLANG_ENGLISH_USA
    '--09----        = LANG_ENGLISH
    ' ----04E4 = 1252 = Codepage for Windows:Multilingual
    Do While Len(Lang_Charset_String) < 8
        Lang_Charset_String = "0" & Lang_Charset_String
    Loop

    List1.Clear
    Dim strVersionInfo(7) As String
    strVersionInfo(0) = "CompanyName"
    strVersionInfo(1) = "FileDescription"
    strVersionInfo(2) = "FileVersion"
    strVersionInfo(3) = "InternalName"
    strVersionInfo(4) = "LegalCopyright"
    strVersionInfo(5) = "OriginalFileName"
    strVersionInfo(6) = "ProductName"
    strVersionInfo(7) = "ProductVersion"
    Dim i As Integer
    Dim strTemp As String
    For i = 0 To 7
        Buffer = String(255, 0)
        strTemp = "\StringFileInfo\" & Lang_Charset_String _
        & "\" & strVersionInfo(i)
        rc = VerQueryValue(sBuffer(0), strTemp, _
        lVerPointer, lBufferLen)
        If rc = 0 Then
            MsgBox "VerQueryValue failed at" & i
        Exit Sub
        End If

        lstrcpy Buffer, lVerPointer
        Buffer = Mid$(Buffer, 1, InStr(Buffer, Chr(0)) - 1)
        List1.AddItem strVersionInfo(i) & ": " & Buffer
    Next i
End Sub



Sun, 02 Jun 2002 03:00:00 GMT  
 file version!!!

--------------16D81B8DAEF7219F1326E4EE
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

The following code allows to get the version information on a specific file.
It works only if you place the file in ..\system32 directory: If I change the
code as follows:
FullFileName = "c:\test\myprogram.exe" it down't work

Please help and ccmail me just in case I miss your email in the newsgroup.

Thanks

afh

Private Sub Command1_Click()
   Dim Buffer As String
   Dim rc As Long
   Dim FullFileName As String

   '*** We will check the FileDescription of the gdi32.dll****
   Buffer = String(255, 0)
   rc = GetSystemDirectory(Buffer, Len(Buffer))
   Buffer = LCase$(Mid$(Buffer, 1, InStr(Buffer, Chr(0)) - 1))
   FullFileName = Buffer & "\gdi32.dll"
   FullFileName = "c:\predator\rel.2_1\pblotter.exe"
   Dim lBufferLen As Long, lDummy As Long
   '*** Get size ****
   lBufferLen = GetFileVersionInfoSize(FullFileName, lDummy)
   If lBufferLen < 1 Then
      MsgBox "No Version Info available!"
      Exit Sub
   End If

   Dim sBuffer()  As Byte
   ReDim sBuffer(lBufferLen)
   rc = GetFileVersionInfo(FullFileName, 0&, lBufferLen, _
        sBuffer(0))
   If rc = 0 Then
      MsgBox "GetFileVersionInfo failed."
      Exit Sub
   End If

   Dim lVerPointer As Long

   rc = VerQueryValue(sBuffer(0), "\VarFileInfo\Translation", _
        lVerPointer, lBufferLen)
   If rc = 0 Then
      MsgBox "VerQueryValue failed."
      Exit Sub
   End If
   'lVerPointer is a pointer to four 4 bytes of Hex number,
   'first two bytes are language id, and last two bytes are code
   'page. However, Lang_Charset_String needs a  string of
   '4 hex digits, the first two characters correspond to the
   'language id and last two the last two character correspond
   'to the code page id.

   Dim bytebuffer(255) As Byte
   MoveMemory bytebuffer(0), lVerPointer, lBufferLen
   Dim Lang_Charset_String As String
   Dim HexNumber As Long

    HexNumber = bytebuffer(2) + bytebuffer(3) * &H100 + _
        bytebuffer(0) * &H10000 + bytebuffer(1) * &H1000000
    Lang_Charset_String = Hex(HexNumber)
    'now we change the order of the language id and code page
    'and convert it into a string representation.
    'For example, it may look like 040904E4
    'Or to pull it all apart:
    '04------        = SUBLANG_ENGLISH_USA
    '--09----        = LANG_ENGLISH
    ' ----04E4 = 1252 = Codepage for Windows:Multilingual
    Do While Len(Lang_Charset_String) < 8
        Lang_Charset_String = "0" & Lang_Charset_String
    Loop

    List1.Clear
    Dim strVersionInfo(7) As String
    strVersionInfo(0) = "CompanyName"
    strVersionInfo(1) = "FileDescription"
    strVersionInfo(2) = "FileVersion"
    strVersionInfo(3) = "InternalName"
    strVersionInfo(4) = "LegalCopyright"
    strVersionInfo(5) = "OriginalFileName"
    strVersionInfo(6) = "ProductName"
    strVersionInfo(7) = "ProductVersion"
    Dim i As Integer
    Dim strTemp As String
    For i = 0 To 7
        Buffer = String(255, 0)
        strTemp = "\StringFileInfo\" & Lang_Charset_String _
        & "\" & strVersionInfo(i)
        rc = VerQueryValue(sBuffer(0), strTemp, _
        lVerPointer, lBufferLen)
        If rc = 0 Then
            MsgBox "VerQueryValue failed at" & i
        Exit Sub
        End If

        lstrcpy Buffer, lVerPointer
        Buffer = Mid$(Buffer, 1, InStr(Buffer, Chr(0)) - 1)
        List1.AddItem strVersionInfo(i) & ": " & Buffer
    Next i
End Sub

--------------16D81B8DAEF7219F1326E4EE
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hi,
<p>The following code allows to get the version information on a specific
file. It works only if you place the file in ..\system32 directory:
<br>If I change the code as follows:
<br><i>FullFileName = "c:\test\myprogram.exe" it down't work</i><i></i>
<p>Please help and ccmail me just in case I miss your email in the newsgroup.
<p>Thanks
<p>afh
<p><b><i>Private Sub Command1_Click()</i></b>
<br><b><i>&nbsp;&nbsp; Dim Buffer As String</i></b>
<br><b><i>&nbsp;&nbsp; Dim rc As Long</i></b>
<br><b><i>&nbsp;&nbsp; Dim FullFileName As String</i></b>
<br><b><i>&nbsp;</i></b>
<br><b><i>&nbsp;&nbsp; '*** We will check the FileDescription of the
gdi32.dll****</i></b>
<br><b><i>&nbsp;&nbsp; Buffer = String(255, 0)</i></b>
<br><b><i>&nbsp;&nbsp; rc = GetSystemDirectory(Buffer, Len(Buffer))</i></b>
<br><b><i>&nbsp;&nbsp; Buffer = LCase$(Mid$(Buffer, 1, InStr(Buffer, Chr(0))
- 1))</i></b>
<br><b><i>&nbsp;&nbsp; FullFileName = Buffer &amp; "\gdi32.dll"</i></b>
<br><b><i>&nbsp;&nbsp; FullFileName =
"c:\predator\rel.2_1\pblotter.exe"</i></b
<br><b><i>&nbsp;&nbsp; Dim lBufferLen As Long, lDummy As Long</i></b>
<br><b><i>&nbsp;&nbsp; '*** Get size ****</i></b>
<br><b><i>&nbsp;&nbsp; lBufferLen = GetFileVersionInfoSize(FullFileName,
lDummy)</i></b>
<br><b><i>&nbsp;&nbsp; If lBufferLen &lt; 1 Then</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "No Version Info
available!"</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub</i></b>
<br><b><i>&nbsp;&nbsp; End If</i></b>
<br><b><i>&nbsp;</i></b>
<br><b><i>&nbsp;&nbsp; Dim sBuffer()&nbsp; As Byte</i></b>
<br><b><i>&nbsp;&nbsp; ReDim sBuffer(lBufferLen)</i></b>
<br><b><i>&nbsp;&nbsp; rc = GetFileVersionInfo(FullFileName, 0&amp;,
lBufferLen,
_</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sBuffer(0))</i></b>
<br><b><i>&nbsp;&nbsp; If rc = 0 Then</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "GetFileVersionInfo
failed."</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub</i></b>
<br><b><i>&nbsp;&nbsp; End If</i></b>
<br><b><i>&nbsp;</i></b>
<br><b><i>&nbsp;&nbsp; Dim lVerPointer As Long</i></b>
<br><b><i>&nbsp;</i></b>
<br><b><i>&nbsp;&nbsp; rc = VerQueryValue(sBuffer(0),
"\VarFileInfo\Translation",
_</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lVerPointer,
lBufferLen)</i></b>
<br><b><i>&nbsp;&nbsp; If rc = 0 Then</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MsgBox "VerQueryValue
failed."</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub</i></b>
<br><b><i>&nbsp;&nbsp; End If</i></b>
<br><b><i>&nbsp;&nbsp; 'lVerPointer is a pointer to four 4 bytes of Hex
number,</i></b>
<br><b><i>&nbsp;&nbsp; 'first two bytes are language id, and last two bytes
are code</i></b>
<br><b><i>&nbsp;&nbsp; 'page. However, Lang_Charset_String needs a&nbsp;
string of</i></b>
<br><b><i>&nbsp;&nbsp; '4 hex digits, the first two characters correspond
to the</i></b>
<br><b><i>&nbsp;&nbsp; 'language id and last two the last two character
correspond</i></b>
<br><b><i>&nbsp;&nbsp; 'to the code page id.</i></b>
<br><b><i>&nbsp;</i></b>
<br><b><i>&nbsp;&nbsp; Dim bytebuffer(255) As Byte</i></b>
<br><b><i>&nbsp;&nbsp; MoveMemory bytebuffer(0), lVerPointer,
lBufferLen</i></b>
<br><b><i>&nbsp;&nbsp; Dim Lang_Charset_String As String</i></b>
<br><b><i>&nbsp;&nbsp; Dim HexNumber As Long</i></b>
<br><b><i>&nbsp;</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; HexNumber = bytebuffer(2) + bytebuffer(3)
* &amp;H100 + _</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bytebuffer(0) *
&amp;H10000
+ bytebuffer(1) * &amp;H1000000</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; Lang_Charset_String = Hex(HexNumber)</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; 'now we change the order of the language id
and code page</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; 'and convert it into a string
representation.</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; 'For example, it may look like 040904E4</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; 'Or to pull it all apart:</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;
'04------&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;
= SUBLANG_ENGLISH_USA</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;
'--09----&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;
= LANG_ENGLISH</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; ' ----04E4 = 1252 = Codepage for
Windows:Multilingual</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; Do While Len(Lang_Charset_String) &lt; 8</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Lang_Charset_String
= "0" &amp; Lang_Charset_String</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; Loop</i></b>
<br><b><i>&nbsp;</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; List1.Clear</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; Dim strVersionInfo(7) As String</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; strVersionInfo(0) = "CompanyName"</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; strVersionInfo(1) = "FileDescription"</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; strVersionInfo(2) = "FileVersion"</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; strVersionInfo(3) = "InternalName"</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; strVersionInfo(4) = "LegalCopyright"</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; strVersionInfo(5) = "OriginalFileName"</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; strVersionInfo(6) = "ProductName"</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; strVersionInfo(7) = "ProductVersion"</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; Dim i As Integer</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; Dim strTemp As String</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp; For i = 0 To 7</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Buffer = String(255,
0)</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strTemp =
"\StringFileInfo\"
&amp; Lang_Charset_String _</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &amp; "\" &amp;
strVersionInfo(i)</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rc =
VerQueryValue(sBuffer(0),
strTemp, _</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lVerPointer,
lBufferLen)</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If rc = 0 Then</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
MsgBox "VerQueryValue failed at" &amp; i</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Sub</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If</i></b>
<br><b><i>&nbsp;</i></b>
<br><b><i>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lstrcpy Buffer,
lVerPointer</i></b> ...

read more »



Sun, 02 Jun 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. How to get File Version of a file?

2. how do I check XL file version programatically?

3. Retrieving file version

4. CHM file version?

5. Getting driver file version information via vbscript or VB

6. Getting .exe file version properties?

7. Getting a files version

8. Need to determine executable file version

9. File version and/or revision

10. file version!!

11. Determining file Version via VB(word 95, 97, Excel 95 97)

12. Get File Version

 

 
Powered by phpBB® Forum Software