Click here to Skip to main content
Licence 
First Posted 22 Dec 2006
Views 18,641
Bookmarked 13 times

Version reading component (as in Explorer's Version tab)

By | 1 Jan 2007 | Article
Version APIs wrapped in a simple component.

Sample Image

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.

// use this array to extend for more fields
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")
                                    };
// use this enumeration along with above array
enum VersionFieldEnum
{
    Comments,
    CompanyName,
    FileDescription,
    FileVersion,
    InternalName,
    LegalCopyright,
    LegalTrademarks,
    OriginalFilename,
    PrivateBuild, 
    ProductName,
    ProductVersion,
    SpecialBuild,
    MaxVersionFields
};

History

1 Jan 2007 - updated downloads

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Masoom Shaikh



India India

Member

label4: C,C++,MFC,ATL,COM,C#

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralSet file Info instead of Geting it PinmemberDaniel Ortega23:35 18 Jan '07  
AnswerRe: Set file Info instead of Geting it PinmemberMasoom Shaikh0:07 19 Jan '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web03 | 2.5.120517.1 | Last Updated 2 Jan 2007
Article Copyright 2006 by Masoom Shaikh
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid