【发布时间】:2011-03-29 20:31:57
【问题描述】:
在 C# 中,我如何以编程方式知道操作系统是 x64 还是 x86
我在网上找到了这个API方法,但是不行
[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;
}
}
提前致谢。
【问题讨论】:
-
它返回的错误是什么?你能发布 IsWow64Process API 的返回值吗?另外,您的 .NET DLL 是否编译为 AnyCPU?
-
另外,尝试搜索 - bing 会返回 stackoverflow.com/questions/336633/… 作为结果。
-
@obelix: 没有错误,但我的操作系统版本是 64,它返回 false
-
Homam,如果您为 AnyCPU 编译,那么您的进程很可能是本机 64 位进程,而不是在 WoW64 下。在 64 位操作系统上,该函数很可能是错误的。您只检查了您的流程是否正在被模拟——它可能是本机的。