--------------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> Dim Buffer As String</i></b>
<br><b><i> Dim rc As Long</i></b>
<br><b><i> Dim FullFileName As String</i></b>
<br><b><i> </i></b>
<br><b><i> '*** We will check the FileDescription of the
gdi32.dll****</i></b>
<br><b><i> Buffer = String(255, 0)</i></b>
<br><b><i> rc = GetSystemDirectory(Buffer, Len(Buffer))</i></b>
<br><b><i> Buffer = LCase$(Mid$(Buffer, 1, InStr(Buffer, Chr(0))
- 1))</i></b>
<br><b><i> FullFileName = Buffer & "\gdi32.dll"</i></b>
<br><b><i> FullFileName =
"c:\predator\rel.2_1\pblotter.exe"</i></b
<br><b><i> Dim lBufferLen As Long, lDummy As Long</i></b>
<br><b><i> '*** Get size ****</i></b>
<br><b><i> lBufferLen = GetFileVersionInfoSize(FullFileName,
lDummy)</i></b>
<br><b><i> If lBufferLen < 1 Then</i></b>
<br><b><i> MsgBox "No Version Info
available!"</i></b>
<br><b><i> Exit Sub</i></b>
<br><b><i> End If</i></b>
<br><b><i> </i></b>
<br><b><i> Dim sBuffer() As Byte</i></b>
<br><b><i> ReDim sBuffer(lBufferLen)</i></b>
<br><b><i> rc = GetFileVersionInfo(FullFileName, 0&,
lBufferLen,
_</i></b>
<br><b><i> sBuffer(0))</i></b>
<br><b><i> If rc = 0 Then</i></b>
<br><b><i> MsgBox "GetFileVersionInfo
failed."</i></b>
<br><b><i> Exit Sub</i></b>
<br><b><i> End If</i></b>
<br><b><i> </i></b>
<br><b><i> Dim lVerPointer As Long</i></b>
<br><b><i> </i></b>
<br><b><i> rc = VerQueryValue(sBuffer(0),
"\VarFileInfo\Translation",
_</i></b>
<br><b><i> lVerPointer,
lBufferLen)</i></b>
<br><b><i> If rc = 0 Then</i></b>
<br><b><i> MsgBox "VerQueryValue
failed."</i></b>
<br><b><i> Exit Sub</i></b>
<br><b><i> End If</i></b>
<br><b><i> 'lVerPointer is a pointer to four 4 bytes of Hex
number,</i></b>
<br><b><i> 'first two bytes are language id, and last two bytes
are code</i></b>
<br><b><i> 'page. However, Lang_Charset_String needs a
string of</i></b>
<br><b><i> '4 hex digits, the first two characters correspond
to the</i></b>
<br><b><i> 'language id and last two the last two character
correspond</i></b>
<br><b><i> 'to the code page id.</i></b>
<br><b><i> </i></b>
<br><b><i> Dim bytebuffer(255) As Byte</i></b>
<br><b><i> MoveMemory bytebuffer(0), lVerPointer,
lBufferLen</i></b>
<br><b><i> Dim Lang_Charset_String As String</i></b>
<br><b><i> Dim HexNumber As Long</i></b>
<br><b><i> </i></b>
<br><b><i> HexNumber = bytebuffer(2) + bytebuffer(3)
* &H100 + _</i></b>
<br><b><i> bytebuffer(0) *
&H10000
+ bytebuffer(1) * &H1000000</i></b>
<br><b><i> Lang_Charset_String = Hex(HexNumber)</i></b>
<br><b><i> 'now we change the order of the language id
and code page</i></b>
<br><b><i> 'and convert it into a string
representation.</i></b>
<br><b><i> 'For example, it may look like 040904E4</i></b>
<br><b><i> 'Or to pull it all apart:</i></b>
<br><b><i>
'04------  
;
= SUBLANG_ENGLISH_USA</i></b>
<br><b><i>
'--09----  
;
= LANG_ENGLISH</i></b>
<br><b><i> ' ----04E4 = 1252 = Codepage for
Windows:Multilingual</i></b>
<br><b><i> Do While Len(Lang_Charset_String) < 8</i></b>
<br><b><i> Lang_Charset_String
= "0" & Lang_Charset_String</i></b>
<br><b><i> Loop</i></b>
<br><b><i> </i></b>
<br><b><i> List1.Clear</i></b>
<br><b><i> Dim strVersionInfo(7) As String</i></b>
<br><b><i> strVersionInfo(0) = "CompanyName"</i></b>
<br><b><i> strVersionInfo(1) = "FileDescription"</i></b>
<br><b><i> strVersionInfo(2) = "FileVersion"</i></b>
<br><b><i> strVersionInfo(3) = "InternalName"</i></b>
<br><b><i> strVersionInfo(4) = "LegalCopyright"</i></b>
<br><b><i> strVersionInfo(5) = "OriginalFileName"</i></b>
<br><b><i> strVersionInfo(6) = "ProductName"</i></b>
<br><b><i> strVersionInfo(7) = "ProductVersion"</i></b>
<br><b><i> Dim i As Integer</i></b>
<br><b><i> Dim strTemp As String</i></b>
<br><b><i> For i = 0 To 7</i></b>
<br><b><i> Buffer = String(255,
0)</i></b>
<br><b><i> strTemp =
"\StringFileInfo\"
& Lang_Charset_String _</i></b>
<br><b><i> & "\" &
strVersionInfo(i)</i></b>
<br><b><i> rc =
VerQueryValue(sBuffer(0),
strTemp, _</i></b>
<br><b><i> lVerPointer,
lBufferLen)</i></b>
<br><b><i> If rc = 0 Then</i></b>
<br><b><i>
MsgBox "VerQueryValue failed at" & i</i></b>
<br><b><i> Exit Sub</i></b>
<br><b><i> End If</i></b>
<br><b><i> </i></b>
<br><b><i> lstrcpy Buffer,
lVerPointer</i></b>
... read more »