How to get computer information? [32 bit or 64 bit]

How can I get information about the type of Windows OS? Is it 32-bit or 64-bit? How can I get this information programmatically?

+7
delphi 32bit-64bit delphi-2007
Mar 26 '10 at 14:27
source share
8 answers

You need to use GetProcAddress() to check the availability of the IsWow64Process() function at run time, for example:

 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; 

because this feature is only available on versions of Windows that have a 64-bit flavor. An external declaration will prevent your application from running on Windows 2000 or Windows XP prior to SP2.

Edit:

Chris posted a comment on caching the result for performance reasons. This may not be necessary for this particular API function, because kernel32.dll will always be there (and I can’t imagine a program that even loads without it), but for other functions it could be otherwise. So, here is the version that caches the result of the function:

 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; 

Caching this function is safe, because the API function will either be there or not, and its result cannot change with the same Windows installation. It’s even safe to call from multiple threads simultaneously, since two threads, finding WasCalled , which will be False , will call the function, write the same result to the same memory location, and only after that set WasCalled to True .

+6
Mar 26
source share
 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; 
+12
Mar 26 '10 at 2:52 p.m.
source share

If you are running Windows and b) you can access the registry, then HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Windows NT \ CurrentVersion should be informative.

+3
Mar 26
source share

In addition to IsWow64Process you might be interested in the GetNativeSystemInfo API function (defined in the Windows module) to learn more about the processor you are on (or you can use the assembly and CPUID ).

+1
Mar 26 '10 at 16:34
source share

I do not know how to call Win32 function in Delphi.

But if you are writing a 32-bit program, you can call the Win32 API IsWow64Process to find out if you are on a 64-bit OS.

Of course, if you are writing a 64-bit exe, it will only work on 64-bit Windows, so there is no need to ask.

0
Mar 26 '10 at
source share

// not verified, but you can try this

 is64 := (Environment.GetEnvironmentVariable('ProgramW6432') <> ''); 
0
Mar 18 '13 at 17:08
source share

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; 

Example

 lbl1.Caption := IsWin64Or32; 
0
Apr 21 '14 at 10:16
source share
 function TForm2.Arch: string; begin if TOSVersion.Architecture=arIntelX86 then Result := '32-bit' Else Result := '64-bit' end; 
0
Nov 16 '14 at 9:12
source share



All Articles