目前我对通过本机 .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 资源管理器。
有 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 Vista
...应用程序要么没有清单,要么明确针对 Vista 进行了清单。
Windows 8
、
Windows 8.1
...这些版本明确体现了应用程序。
请注意,Windows PowerShell (
powershell.exe
) 和PowerShell (Core) 7+ (
pwsh.exe
)都适用于 Windows 10+,这就是您在输出中看到
10.0
值的原因您在 PowerShell 会话中(进程内)运行的命令。这同样适用于使用文件资源管理器 GUI 来检查文件属性。