.exe Properties, Version Tab, Comments
.exe Properties, Version Tab, Comments
(OP)
Hello all, I'm a beginner VB6 programmer and I don't really know the slightest thing about APIs. Only some basics.
However, I'm trying to get my VB program to get the properties of other .exe files.
I have succeeded in using a couple of APIs to shell the properties window of .exe files.
But what I need is much more specific.
I'm trying to get the Comments in the 'Other version information' section in the Version tab of the Properties shell.
--Properties
----Version
------Other version Information
--------Comments
And to be more specific; I'm trying to get those comments of VB6 .exe files. That is, .exe files programmed in VB6.
I know there must be an API that would get me that information but I just can't seem to find it. If anybody can help me out on this I would really appreciate that he/she be elaborate on how to use it. Because using APIs in functions seems to be quite complicated.
Thank you all for taking the time to read my post.
Greetings
Ahmad
However, I'm trying to get my VB program to get the properties of other .exe files.
I have succeeded in using a couple of APIs to shell the properties window of .exe files.
But what I need is much more specific.
I'm trying to get the Comments in the 'Other version information' section in the Version tab of the Properties shell.
--Properties
----Version
------Other version Information
--------Comments
And to be more specific; I'm trying to get those comments of VB6 .exe files. That is, .exe files programmed in VB6.
I know there must be an API that would get me that information but I just can't seem to find it. If anybody can help me out on this I would really appreciate that he/she be elaborate on how to use it. Because using APIs in functions seems to be quite complicated.
Thank you all for taking the time to read my post.
Greetings
Ahmad
RE: .exe Properties, Version Tab, Comments
RE: .exe Properties, Version Tab, Comments
Here is a generalized version of this code which can be used to query any information from the "Other version information" section.
___
Option Explicit
Private Declare Function VerQueryValue Lib "version" Alias "VerQueryValueA" (pBlock As Any, ByVal lpSubBlock As String, lplpBuffer As Long, puLen As Long) As Long
Private Declare Function GetFileVersionInfoSize Lib "version" Alias "GetFileVersionInfoSizeA" (ByVal lptstrFilename As String, lpdwHandle As Long) As Long
Private Declare Function GetFileVersionInfo Lib "version" Alias "GetFileVersionInfoA" (ByVal lptstrFilename As String, ByVal dwHandle As Long, ByVal dwLen As Long, lpData As Any) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Function GetVersionProperty(FileName As String, Property As String) As String
Dim VerInfoSize As Long, lpdwHandle As Long, Buffer() As Byte
Dim strLangCharSet As String, lpData As Long, cbData As Long
'Query the size of the version info data
VerInfoSize = GetFileVersionInfoSize(FileName, lpdwHandle)
If VerInfoSize = 0 Then Exit Function
'Create the version info buffer and query the data
ReDim Buffer(0 To VerInfoSize - 1)
If GetFileVersionInfo(FileName, 0, VerInfoSize, Buffer(0)) = 0 Then Exit Function
'Query the language/character set identifier
If VerQueryValue(Buffer(0), "\VarFileInfo\Translation", lpData, cbData) = 0 Then Exit Function
CopyMemory lpData, ByVal lpData, 4
strLangCharSet = Hex$(lpData) 'convert to hex
strLangCharSet = Right$("00000000" & strLangCharSet, 8) 'pad leading zeroes
strLangCharSet = Right$(strLangCharSet, 4) & Left$(strLangCharSet, 4) 'swap the upper and lower words
'Query the original file name
Dim S As String
If VerQueryValue(Buffer(0), "\StringFileInfo\" & strLangCharSet & "\" & Property, lpData, cbData) = 0 Then Exit Function
S = Space$(cbData)
CopyMemory ByVal S, ByVal lpData, cbData
GetVersionProperty = Left$(S, InStr(S, vbNullChar) - 1)
End Function
Private Sub Form_Load()
MsgBox GetVersionProperty("C:\myapp.exe", "Comments") 'get 'Comments' field.
End Sub
RE: .exe Properties, Version Tab, Comments
I have tried the code but my program crashes when I use the function.
It crashes on this line:
CopyMemory lpData, ByVal lpData, 4
Any guidance on this?
Ahmad
RE: .exe Properties, Version Tab, Comments
However, I did some modification in the following portion of the code as mentioned below.
Change the lines:
___
'Query the original file name
Dim S As String
If VerQueryValue(Buffer(0), "\StringFileInfo\" & strLangCharSet & "\" & Property, lpData, cbData) = 0 Then Exit Function
S = Space$(cbData)
CopyMemory ByVal S, ByVal lpData, cbData
___
as below:
___
'Query the requested version value
Dim S As String * 1000
If VerQueryValue(Buffer(0), "\StringFileInfo\" & strLangCharSet & "\" & Property, lpData, cbData) = 0 Then Exit Function
CopyMemory ByVal S, ByVal lpData, cbData
___
This prevents the code from crashing in some cases if the requested value is not present in the version resource.
As a precaution, make sure that all API functions are declared *exactly* the same way as above.
RE: .exe Properties, Version Tab, Comments
Thank you loads for your help and time.
It's working great!
And actually both ways work. I probably mistyped something in the declarations even though I used the API Viewer...
Apparently you are more trustworthy
Thanks again