我该如何获取Windows操作系统类型的信息?是32位还是64位?我该如何以编程的方式获取这些信息?
我该如何获取Windows操作系统类型的信息?是32位还是64位?我该如何以编程的方式获取这些信息?
function IsWin64: Boolean;
var
IsWow64Process : function(hProcess : THandle; var Wow64Process : BOOL): BOOL; stdcall;
Wow64Process : BOOL;
begin
Result := False;
IsWow64Process := GetProcAddress(GetModuleHandle(Kernel32), 'IsWow64Process');
if Assigned(IsWow64Process) then begin
if IsWow64Process(GetCurrentProcess, Wow64Process) then begin
Result := Wow64Process;
end;
end;
end;
您需要使用 GetProcAddress()
在运行时检查 IsWow64Process()
函数的可用性,如下所示:
function Is64BitWindows: boolean;
type
TIsWow64Process = function(hProcess: THandle; var Wow64Process: BOOL): BOOL;
stdcall;
var
DLLHandle: THandle;
pIsWow64Process: TIsWow64Process;
IsWow64: BOOL;
begin
Result := False;
DllHandle := LoadLibrary('kernel32.dll');
if DLLHandle <> 0 then begin
pIsWow64Process := GetProcAddress(DLLHandle, 'IsWow64Process');
Result := Assigned(pIsWow64Process)
and pIsWow64Process(GetCurrentProcess, IsWow64) and IsWow64;
FreeLibrary(DLLHandle);
end;
end;
function Is64BitWindows: boolean;
type
TIsWow64Process = function(hProcess: THandle; var Wow64Process: BOOL): BOOL;
stdcall;
var
DLLHandle: THandle;
pIsWow64Process: TIsWow64Process;
const
WasCalled: BOOL = False;
IsWow64: BOOL = False;
begin
if not WasCalled then begin
DllHandle := LoadLibrary('kernel32.dll');
if DLLHandle <> 0 then begin
pIsWow64Process := GetProcAddress(DLLHandle, 'IsWow64Process');
if Assigned(pIsWow64Process) then
pIsWow64Process(GetCurrentProcess, IsWow64);
WasCalled := True;
FreeLibrary(DLLHandle);
end;
end;
Result := IsWow64;
end;
WasCalled
为 False
的线程都会调用该函数,将相同的结果写入相同的内存位置,仅在之后设置 WasCalled
为 True
。function TForm2.Arch: string;
begin
if TOSVersion.Architecture=arIntelX86 then
Result := '32-bit' Else Result := '64-bit'
end;
for delphi XE+
Uses System.SysUtils
Function IsWin64Or32: string;
Begin
if Pos( '64-bit', TOSVersion.ToString ) > 0 then
Result := '64-bit'
Else
Result := '32-bit';
End;
lbl1.Caption := IsWin64Or32;
IsWow64Process
函数外,GetNativeSystemInfo API函数(定义在Windows
单元中)也可能引起您的兴趣,以了解更多有关当前CPU的信息(或者您可以使用汇编和CPUID
)。//没有测试过,但你可以试试这个
is64 := (Environment.GetEnvironmentVariable('ProgramW6432') <> '');
delphi
,并没有提到 .net 或 Java。因此,您不能假设 Environment
可用。请在回答问题之前阅读标签,确保您的答案适用于它们。如果您不确定,您可能不应该回答这个问题。 :-) - Ken White