在C#中,我怎么能知道编程如果操作系统是基于x64或x86

编程入门 行业动态 更新时间:2024-10-14 12:24:20
本文介绍了在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; } }

在此先感谢。

Thanks in advance.

推荐答案

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

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

这是它如何impemented

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:40:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1577537.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作系统   是基于   我怎么能

发布评论

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

>www.elefans.com

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