×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

.exe Properties, Version Tab, Comments

.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

RE: .exe Properties, Version Tab, Comments

You might want to post your question in forum711

RE: .exe Properties, Version Tab, Comments

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.
___

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

(OP)
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

RE: .exe Properties, Version Tab, Comments

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:
___

'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

(OP)
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

clown

Thanks again

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close