gpt4 book ai didi

c# - 如何使用 .NET 检测 Windows 64 位平台?

转载 作者:行者123 更新时间:2023-11-30 13:05:30 24 4
gpt4 key购买 nike

.NET 中2.0 C#应用程序我使用如下代码检测操作系统平台:

string os_platform = System.Environment.OSVersion.Platform.ToString();

这将返回“Win32NT”。问题是即使在 64 位 Windows Vista 上运行时它也会返回“Win32NT”。

有没有其他方法可以知道正确的平台(32 位或 64 位)?

请注意,当在 Windows 64 位上作为 32 位应用程序运行时,它也应该检测 64 位。

最佳答案

.NET 4 在环境类中有两个新属性,Is64BitProcessIs64BitOperatingSystem .有趣的是,如果您使用 Reflector,您会发现它们在 32 位和 64 位版本的 mscorlib 中的实现方式不同。 32 位版本为 Is64BitProcess 返回 false,并通过 P/Invoke 为 Is64BitOperatingSystem 调用 IsWow64Process。 64 位版本只为两者返回 true。

关于c# - 如何使用 .NET 检测 Windows 64 位平台?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4356100/

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