Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: VB7
Expertise: Intermediate
Aug 8, 2002

Retrieve file version information

The System.Diagnostics.FileVersionInfo class lets you easily read file version information without having to call Windows API functions (as you have to do under previous VB versions). This class has a static GetVersionInfo method that returns a FileVersionInfo object related to a given file. Once you have such an object, retrieving version information is as easy as calling its properties. Here's a code snippet that shows what kind of properties you can query:

' get information about Microsoft Word
Dim exefile As String = "C:\Program Files\Microsoft Office\Office\Winword.exe"
Dim fvi As FileVersionInfo = FileVersionInfo.GetVersionInfo(exefile)

Console.WriteLine("ProductName: {0}", fvi.ProductName)
Console.WriteLine("ProductVersion: {0}", fvi.ProductVersion)
Console.WriteLine("CompanyName: {0}", fvi.CompanyName)
Console.WriteLine("FileVersion: {0}", fvi.FileVersion)
Console.WriteLine("FileDescription: {0}", fvi.FileDescription)
Console.WriteLine("OriginalFilename: {0}", fvi.OriginalFilename)
Console.WriteLine("LegalCopyright: {0}", fvi.LegalCopyright)
Console.WriteLine("LegalTrademarks: {0}", fvi.LegalTrademarks)
Console.WriteLine("Comments: {0}", fvi.Comments)
Console.WriteLine("InternalName: {0}", fvi.InternalName)
You can also query individual version numbered components with the ProductMajorPart, ProductMinorPart, ProductBuildPart, and ProductPrivatePart (for the product version) and FileMajorPart, FileMinorPart, FileBuildPart, and FilePrivatePart (for the file version) properties. There are also five boolean properties that return additional information about the executable:

Console.WriteLine("IsDebug: {0}", fvi.IsDebug)
Console.WriteLine("IsPatched: {0}", fvi.IsPatched)
Console.WriteLine("IsPreRelease: {0}", fvi.IsPreRelease)
Console.WriteLine("IsPrivateBuild: {0}", fvi.IsPrivateBuild)
Console.WriteLine("IsSpecialBuild: {0}", fvi.IsSpecialBuild)
Francesco Balena
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date