Different version information of c# (.net7) / powershell / explorer

103 Views Asked by At

currently i am a little bit confused about the versions i am able to get via native .net (C#), powershell and the windows explorer.

As you can see in the screenshot the C#-Code determines FileMajorPart=6 and FileMinorPart=2. I espected at least Major Version 10. Why is powershell displaying the correct versions even when using the same functions?

IDE screenshot

Also... It seems, that this only happens for some special files. Also calc.exe displays a wrong version. Other .exe-Files are displayed correctly.

C#:

using System.Diagnostics;

FileVersionInfo test = FileVersionInfo.GetVersionInfo(@"c:\windows\system32\notepad.exe");

Result:

-       test    {File:             c:\windows\system32\notepad.exe
InternalName:     Notepad
OriginalFilename: NOTEPAD.EXE.MUI
FileVersion:      10.0.19041.1 (WinBuild.160101.0800)
FileDescription:  Editor
Product:          Betriebssystem Microsoft® Windows®
ProductVersion:   10.0.19041.1
Debug:            False
Patched:          False
PreRelease:       False
PrivateBuild:     False
SpecialBuild:     False
Language:         Deutsch (Deutschland)
}   System.Diagnostics.FileVersionInfo
       ...
        FileMajorPart   6   int
        FileMinorPart   2   int
        FileName    "c:\\windows\\system32\\notepad.exe"    string
        FilePrivatePart 3636    int
        FileVersion "10.0.19041.1 (WinBuild.160101.0800)"   string
        ...
        ProductBuildPart    19041   int
        ProductMajorPart    10  int
        ProductMinorPart    0   int
        ProductName "Betriebssystem Microsoft® Windows®"    string
        ProductPrivatePart  3636    int
        ProductVersion  "10.0.19041.1"  string
        SpecialBuild    ""  string

Powershell:

PS C:\> [System.Diagnostics.FileVersionInfo]::GetVersionInfo("c:\windows\system32\notepad.exe") | fl *


FileVersionRaw     : 10.0.19041.3636
ProductVersionRaw  : 10.0.19041.3636
Comments           :
CompanyName        : Microsoft Corporation
FileBuildPart      : 19041
FileDescription    : Editor
FileMajorPart      : 10
FileMinorPart      : 0
FileName           : c:\windows\system32\notepad.exe
FilePrivatePart    : 3636
FileVersion        : 10.0.19041.1 (WinBuild.160101.0800)
InternalName       : Notepad
IsDebug            : False
IsPatched          : False
IsPrivateBuild     : False
IsPreRelease       : False
IsSpecialBuild     : False
Language           : Deutsch (Deutschland)
LegalCopyright     : © Microsoft Corporation. Alle Rechte
                     vorbehalten.
LegalTrademarks    :
OriginalFilename   : NOTEPAD.EXE.MUI
PrivateBuild       :
ProductBuildPart   : 19041
ProductMajorPart   : 10
ProductMinorPart   : 0
ProductName        : Betriebssystem Microsoft® Windows®
ProductPrivatePart : 3636
ProductVersion     : 10.0.19041.1
SpecialBuild       :

Do you have any idea, why this could happen?

I am using .net 7.0 for c#.

Thank you in advance and regards, Wolfgang

I tried using different tools like powershell / windows explorer.

1

There are 1 best solutions below

0
mklement0 On
  • There are Windows system APIs that situationally report legacy information for the sake of backward compatibility, notably with respect to the OS version.

    • This seemingly also applies to the file-version information of executables and libraries that ship with Windows, such as Notepad.

    • A caveat is that the .FileVersion and .ProductVersion properties of the .NET System.Diagnostics.FileVersionInfo type are "cooked" values that mask the legacy behavior, but the underlying version number component-individual properties (.FileMajorPar, .FileMinorPart, ...) do report the legacy values, if applicable.

  • The behavior of these APIs depends on whether the querying application has an application manifest, and, if so, what version of Windows that manifest specifies.

    • Specifically, it is the ID attribute of the supportedOS element that declares the compatible Windows version.

    • In the absence of a manifest, applications see legacy values that applied to Windows Vista, namely 6.2 as the OS version.

    • Operating System Version shows the detailed mapping. Notably, on Windows 11 it is still 10.0 that is reported.

  • To discover the manifested behavior of a given application:

    • Launch the application and keep it open.
    • Start Task Manager (taskmgr.exe) and switch to its Details view (Details view icon in the left sidebar)
    • Right-click on the column headers, click on 'Select columnsand add theOperating system context` column to the view (scroll down until you see it - the list is not sorted by name).
    • You'll see the following:
      • (no value) ... the application is manifested for Windows 10, Windows 11, Windows Server 2016, Windows Server 2019 and Windows Server 2022 (the same GUID is used for all of them).
      • Windows Vista ... the application has either no manifest or was manifested for Vista explicitly.
      • Windows 8, Windows 8.1 ... the application was explicitly manifested for these versions.

Your screenshot implies that the IDE you're using has NO application manifest, which explains the values you're seeing.

Note that both Windows PowerShell (powershell.exe) and PowerShell (Core) 7+ (pwsh.exe) are manifested for Windows 10+, which is why you saw 10.0 values in the output from the command you ran (in-process) in a PowerShell session.

The same applies analogous to using the File Explorer GUI for inspecting file properties.