gpt4 book ai didi

c# - 如何确定处理器是否支持 32 位操作系统上的 64 位

转载 作者:行者123 更新时间:2023-11-30 21:02:54 26 4
gpt4 key购买 nike

目前我正在使用:

ManagementObjectSearcher searcher = 
new ManagementObjectSearcher("Select * FROM WIN32_Processor");
ManagementObjectCollection mObject = searcher.Get();

foreach (ManagementObject obj in mObject)
{
var architecture = obj.GetPropertyValue("Architecture");
}

架构 = 0

article显示 0 表示 x86

计算机运行的处理器是intel core 2 duo E7500

操作系统是 Windows XP 32 位

CPU-Z显示

enter image description here

有没有办法确定 Windows XP 计算机是否具有支持 64 位的处理器?

最佳答案

它可能不理想,但使用 VC++ 等创建( native )DLL 并直接查询处理器的功能是相对简单的。然后可以从您的 C# 应用程序中调用此方法。

以下 C++ 方法在 64 位处理器上运行时返回 true,在仅 32 位处理器上运行时返回 false(无论操作系统是 32 位还是 64 位):

bool __declspec(naked) IsCPU64BitCapable()
{
__asm
{
// Save EBX since it's affected by CPUID
push ebx
// Determine whether the CPU supports retrieving extended feature data
mov eax, 0x80000000
cpuid
cmp eax, 0x80000000
// No extended data => no 64 bit
jbe no_extended_data
// Request extended feature data
mov eax, 0x80000001
cpuid
// Bit 29 of EDX will now indicate whether the CPU is 64 bit capable
mov eax, edx
shr eax, 29
and eax, 1
jmp extended_data
no_extended_data:
xor eax,eax
extended_data:
// Restore EBX
pop ebx
ret
}
}

此方法可以在 C# 中使用:

[DllImport("Test64Bit.dll")]
private static extern bool IsCPU64BitCapable();

关于c# - 如何确定处理器是否支持 32 位操作系统上的 64 位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13163879/

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