I am trying to get the version of Powershell(in this case) FileVersionInfo GetVersionInfo.Below is my code-
static void Main(string[] args)
{
var versionInfo = FileVersionInfo.GetVersionInfo(@"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe");
Console.WriteLine("versionInfo.FileMajorPart "+ versionInfo.FileMajorPart+" versionInfo.FileMinorPart "+ versionInfo.FileMinorPart+" versionInfo.FileBuildPart "+ versionInfo.FileBuildPart+" versionInfo.FilePrivatePart "+versionInfo.FilePrivatePart);
Console.WriteLine("File version-"+ versionInfo.FileVersion);
}
The output I get is-
versionInfo.FileMajorPart 6 versionInfo.FileMinorPart 2 versionInfo.FileBuildPart 14393 versionInfo.FilePrivatePart 0
File version-10.0.14393.0 (rs1_release.160715-1616)
If I open the exe and check the details tab the correct version is 10.0.14393.0.For some of the exes in windows 10 I am getting wrong values like this.What I do not understand is how versionInfo.FileVersion gives the correct result but the FileMajorPart does not.One more strange observation is this works correctly if I just copy the exe file to desktop and try with that path.