在 C# 中,如何以编程方式知道操作系统是 x64 还是 x86

编程入门 行业动态 更新时间:2024-10-14 10:45:35
本文介绍了在 C# 中,如何以编程方式知道操作系统是 x64 还是 x86的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在 C# 中,我如何以编程方式知道操作系统是 x64 还是 x86

In C#, how can I know programmatically if the Operating system is x64 or x86

我在网上找到了这个API方法,但是没有用

I found this API method on the internet, but it doesn't work

[DllImport("kernel32.dll")] public static extern bool IsWow64Process(System.IntPtr hProcess, out bool lpSystemInfo); public static bool IsWow64Process1 { get { bool retVal = false; IsWow64Process(System.Diagnostics.Process.GetCurrentProcess().Handle, out retVal); return retVal; } }

提前致谢.

推荐答案

在 .NET 4.0 中,您可以使用新的 Environment.Is64BitOperatingSystem 属性.

In .NET 4.0 you can use the new Environment.Is64BitOperatingSystem property.

这就是它被阻碍的方式

public static bool Is64BitOperatingSystem { [SecuritySafeCritical] get { bool flag; return ((Win32Native.DoesWin32MethodExist("kernel32.dll", "IsWow64Process") && Win32Native.IsWow64Process(Win32Native.GetCurrentProcess(), out flag)) && flag); } }

使用反射器或类似物来查看它是如何工作的.

Use reflector or similar to see exactly how it works.

更多推荐

在 C# 中,如何以编程方式知道操作系统是 x64 还是 x86

本文发布于:2023-11-11 05:39:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577536.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作系统   方式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!