C# FileVersionInfo.GetVersionInfo (FilePath) behaves strangely

677 views Asked by At

I am trying to read the file version from an exe file. ( - not product version.) I tested two sample codes.

var versionInfo = FileVersionInfo.GetVersionInfo(FilePath);
string Description = versionInfo .FileDescription;
string Company = versionInfo.CompanyName;
//1
string Fileversion1 = string.Format("{0}.{1}.{2}.{3}", versionInfo.FileMajorPart, versionInfo.FileMinorPart, versionInfo.FileBuildPart, versionInfo.FilePrivatePart);
//2
string Fileversion2 = versionInfo.FileVersion;

The result is shown below.

enter image description here

The following figure is an actual property of PowerShell.

enter image description here

MS applications such as notepad, cmd will get the same results as POwershell.

Check Putty with the same code:

enter image description here

I would like to know the file version in the properties of the application.

I have a history of upgrading from Windows8 to Windows10 through a free upgrade to Windows10. Can this behavior affect the outcome?

1

There are 1 answers

1
Nick On

The documentation of property FileVersion is misleading. It makes you think it is a concatenation of major, minor, build and private numbers.

Actually, FileVersion is extracted using a call to a system API function (VerQueryValue), which can returns something different.