devxlogo

Retrieve file version information

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 WordDim exefile As String = "C:Program FilesMicrosoft OfficeOfficeWinword.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)

See also  Why ChatGPT Is So Important Today
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist