c#(.net7)/powershell/explorer不同版本信息

问题描述 投票:0回答:1

目前我对通过本机 .net (C#)、powershell 和 Windows 资源管理器能够获得的版本有点困惑。

正如您在屏幕截图中看到的,C# 代码确定 FileMajorPart=6 和 FileMinorPart=2。我预计至少是主要版本 10。为什么即使使用相同的功能,powershell 也显示正确的版本?

另外...看来,这只发生在某些特殊文件上。 calc.exe 也显示错误的版本。其他 .exe 文件正确显示。

C#:

using System.Diagnostics;

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

结果:

-       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       :

您知道为什么会发生这种情况吗?

我正在使用 .net 7.0 进行 c#。

提前感谢您并致以问候, 沃尔夫冈

我尝试使用不同的工具,如 powershell / windows 资源管理器。

c# .net powershell explorer
1个回答
0
投票
  • Windows 系统 API 会情况地报告旧版信息,以实现向后兼容性,特别是关于 操作系统版本

    • 这似乎也适用于Windows附带的可执行文件和库的文件版本信息,例如记事本。

    • 需要注意的是,.NET

      .FileVersion
      类型的 .ProductVersion
      System.Diagnostics.FileVersionInfo
      属性是“经过处理的”值,它会 mask 遗留行为,但底层版本号组件独立属性 (
      .FileMajorPar 
      .FileMinorPart
      、...)请报告旧值(如果适用)。

  • 这些 API 的行为取决于查询应用程序是否具有应用程序清单,如果有,则清单指定的 Windows 版本。

    • 具体来说,是

      ID
       元素的 
      supportedOS
      属性声明了兼容的 Windows 版本。

    • 缺少清单的情况下,应用程序会看到适用于 Windows Vista 的旧值,即

      6.2
      作为操作系统版本

    • 操作系统版本显示详细映射。值得注意的是,在 Windows 11 上报告的仍然是

      10.0

  • 发现给定应用程序的表现行为

    • 启动应用程序并保持打开状态。
    • 启动任务管理器 (
      taskmgr.exe
      ) 并切换到其
      Details
      视图(左侧边栏中的
    • 右键单击列标题,单击“选择列
      and add the
      操作系统上下文”列查看视图(向下滚动直到看到它 - 该列表按名称排序)。
    • 您将看到以下内容:
      • (无值)...该应用程序适用于 Windows 10、Windows 11、Windows Server 2016、Windows Server 2019 和 Windows Server 2022(所有这些都使用 相同 GUID)。
      • Windows Vista
        ...应用程序要么没有清单,要么明确针对 Vista 进行了清单。
      • Windows 8
        Windows 8.1
         ...这些版本明确体现了应用程序。

您的屏幕截图表明您正在使用的 IDE 没有应用程序清单,这解释了您所看到的值。

请注意,Windows PowerShell (

powershell.exe

) 和 
PowerShell (Core) 7+ (pwsh.exe
) 
都适用于 Windows 10+,这就是您在输出中看到 10.0
 值的原因您在 PowerShell 会话中(进程内)运行的命令。

这同样适用于使用文件资源管理器 GUI 来检查文件属性。

© www.soinside.com 2019 - 2024. All rights reserved.