Introduction
This article presents a simple COM object to read the version information of
a given file. The version information returned is the same as what appears in
the Version tab of file properties in Windows Explorer.
Background
It is fairly easy to use this component. Initially, I designed this code in
C++ as a class, with a constructor taking a filename as the argument. Then, I
decided to make it a COM component to cater to a wider audience (and also so
that I can use it in scripts). It can be used in any language that supports COM
but if you are interested in understanding the Win32 version API, then you may
want to look for the following functions in MSDN:
GetFileVersionInfoSize()
, GetFileVersionInfo()
, and
VerQueryValue()
.
Using the code
Any one familiar with using COM components in VB6, .NET, or C++ shall be able
to use this code. I have provided a working C++ version which will simply print
the version of a file it receives on the command line in CSV (comma separated
values) format. I then use this program in a batch file, using the 'for' command
to generate a *.csv file for all versions of drivers located in
windows\system32\drivers. I like the *.csv format since it is the
easiest way to put your data in Microsoft Excel (or any other program you use
for formatting output to a more appealing one). Currently, only fields mentioned
in MSDN are programmed, but it is easy to build your own version by adding
entries in the VersionFieldArray
and adding another enumeration
value in VersionFieldEnum
. Then, add a property for the same.
const tstring VersionFieldArray[] = {
_T("Comments"),
_T("CompanyName"),
_T("FileDescription"),
_T("FileVersion"),
_T("InternalName"),
_T("LegalCopyright"),
_T("LegalTrademarks"),
_T("OriginalFilename"),
_T("PrivateBuild"),
_T("ProductName"),
_T("ProductVersion"),
_T("SpecialBuild")
};
enum VersionFieldEnum
{
Comments,
CompanyName,
FileDescription,
FileVersion,
InternalName,
LegalCopyright,
LegalTrademarks,
OriginalFilename,
PrivateBuild,
ProductName,
ProductVersion,
SpecialBuild,
MaxVersionFields
};
History
1 Jan 2007 - updated downloads