Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.exe Properties, Version Tab, Comments

Status
Not open for further replies.

debeebop

Programmer
Dec 14, 2005
6
EG
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
 
I posted some code in thread222-696172 for retrieving the original filename of an exe file from version information.

Here is a generalized version of this code which can be used to query any information from the "Other version information" section.
___
[tt]
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[/tt]
 
Thank you Hypetia for the post!

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
 
The code works just fine for me. I tried it in a loop with more than 1500 files in my system32 folder querying different value. It never crashed on the line you indicated.

However, I did some modification in the following portion of the code as mentioned below.

Change the lines:
___
[tt]
'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[/tt]
___

as below:
___
[tt]
'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[/tt]
___

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.
 
Hello Hypetia

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

:eek:)

Thanks again

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top