0

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.

Somesh Dhal
  • 336
  • 2
  • 15
  • Have a look at [this,](https://stackoverflow.com/questions/17688660/getting-the-program-version-of-an-executable-file-like-explorer-does-in-c-sharp), [this](https://stackoverflow.com/questions/11498744/fileversioninfo-retrieving-incorrect-file-version), and [this](https://stackoverflow.com/questions/5460199/fileversioninfo-fileversion-returns-productversion/5460402#5460402) post – boop_the_snoot Dec 04 '17 at 07:40
  • 1
    The above links does not help as the links suggest multiple ways to get the same result .But in this case two of the similar properties are returning different vallues that too for some specific files. – Somesh Dhal Dec 04 '17 at 08:54

0 Answers0