Search Amazon:

Retrieve File Version Information

Executable files, OCXs, DLLs, device drivers, and fonts can contain information about their origin, national language and code page, content, target operating system, version and more. Also, developers can code a comment, description, copyright, trademark and additional info into the executable itself. To see this info, navigate to an executable, right click on it and select properties.

This sample shows how to retrieve this information. All functionality is contained in a class module. Simply call the GetVersionInfo method passing in the path to the file whose information you want to read. Or, you can pass in the Module name of a file that is loaded in memory. For a complete description of the individual file properties retrieved, see the class module.

Retrieve file version information
Download Source Code

Details

Embedded in the various file types that support version information are three different types of version information: A fixed-size data structure containing information such as the file version, the product version, and the target operating system. A variable-length section with information about translation issues, including the default code page and language. Another variable-length section containing language-specific information about the file, such as copyright text, company name, legal trademarks, and so on.

To retrieve this information the GetFileVersionInfoSize, GetFileVersionInfo, and VerQueryInfo APIs are used.

First, the GetLanguageInfo method is invoked to retrieve the entire block of version information from the file. This method calls the GetFileVersionInfoSize API passing it the file name. It returns the number of bytes of version information. An array is dimmed to this size and passed to the GetFileVersionInfo API which gets the version info.

Next the VerQueryValue function is used. VerQueryValue lets you specify several different types of information and returns different file version information data based on your request. The first call to VerQueryValue retrieves language translation/code page information. However, what is retrieved is a memory address of this information. A bit of work, involving the CopyMemory API, is required to grab this data.

The second call to VerQueryValue pulls a fixed-size block of version data containing the file version, product version, target operating system, etc. Again, a bit of manipulation is necessary to process this data. Parsing out the individual values from this version data is straight forward. See the code for details.

To get the information specified by the developer, another call to VerQueryValue is made. This one is wrapped in the GetValue method and is similar to the previous calls.

Instructions

Run the code and navigate to a file.

Sign In
  User Id 
  Password 


Submit Your Own Code and Articles




About TheScarms
About TheScarms

Ask me your programming questions

I read every email and answer all I can.

User Feedback: Be the first to add a comment! Items to Show:     

     
You must log in to post feedback.
Comment:    
 

If you use this code, please mention "www.TheScarms.com"

Email this page


TheScarms AppSentinel lets you securely copy protect and create evaluation versions of your software

TheScarms(tm) AppSentinel lets you quickly and easily create evaluation versions of your software and stop unauthorized copying and unregistered use of your programs!

Get your free
trial copy today!


      The World's Number 1 Web Host

© Copyright 2008 TheScarms