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.
Download Source Code
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.
Run the code and navigate to a file.
|