c# - .NET 应用程序将不同的操作系统版本返回到 Windows 10 上的 PowerShell

标签 c# .net windows powershell windows-10

我正在尝试确定 .NET 应用程序中的操作系统版本,该应用程序已使用 System.Environment.OSVersion 成功确定 Windows 8.1 之前所有版本的 Windows 的版本。

但是,在 Windows 10 上的 .NET 应用程序中调用 System.Environment.OSVersion 时,返回的版本是 Microsoft Windows NT 6.2.9200.0(这正是与 Windows 8.1 上的输出相同)。但是,当通过 PowerShell 调用 [System.Environment]::OSVersion 时,输出为我 Microsoft Windows NT 10.0.10240.0

我的印象是 PowerShell 在幕后使用 .NET 并期望这两个调用返回完全相同的输出。为什么输出存在差异,更重要的是,我如何检测我的应用程序是否在 Windows 10 上运行?

最佳答案

我认为this is the cause :

With the release of Windows 8.1, the behavior of the GetVersion API has changed in the value it will return for the operating system version. The value returned by the GetVersion function now depends on how the application is manifested.

Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2).

关于c# - .NET 应用程序将不同的操作系统版本返回到 Windows 10 上的 PowerShell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32121110/

相关文章:

c# - 南希的主机目录

c# - azure 函数将多个文件上传到 blob 存储

windows - adobe air app可以打包运行在windows 8上吗?

java - 重用 SQLite 连接还是每次都重新连接?

c# - SQL Server 连接超时 C#

c# - 在多个文件中重复使用指令

c# Registry to XML Invalid character 问题

c# - WCF 中的多个基地址和多个端点

.net - 电子邮件附件的自动处理

windows - 如何以编程方式检测操作系统何时完成加载其所有应用程序\服务?