gpt4 book ai didi

c# - System.Environment.OSVersion 返回错误的版本

转载 作者:IT王子 更新时间:2023-10-29 04:30:49 25 4
gpt4 key购买 nike

使用 windows 10,从 windows 8 升级 => 8.1 => 10 当我使用此代码时。

OperatingSystem os = System.Environment.OSVersion;

os.Version = {6.2.9200.0} System.Version

我读这篇文章是因为它的版本是 manifested for但我不明白那是什么意思。

我想要正确的操作系统版本,因为我在 Web 服务上记录用户代理字符串,并且想要正确识别支持的 Windows 版本。使其正确报告正确版本的最简单方法是什么?

最佳答案

除非您使用 list 声明您的应用程序兼容,否则 Windows 10 会返回该字符串。为此,添加一个 app.manifest(右键单击您的项目 -> 添加 -> 新项目 -> 应用程序 list 文件)然后取消注释以下行:

<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />

您可以对 Windows Vista 和 Windows 10 执行相同的操作。所有内容都在同一部分:

<application>
<!-- A list of the Windows versions that this application has been tested on and is
is designed to work with. Uncomment the appropriate elements and Windows will
automatically selected the most compatible environment. -->

<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->

<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->

<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->

<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->

<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />

</application>

现在,当您运行应用程序时,它会报告正确的 10.0.*.0 版本

关于c# - System.Environment.OSVersion 返回错误的版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33328739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com