How to test if windows 32 or 64 bit

Just starting out? Need help? Post your questions and find answers here.
jak64
Enthusiast
Enthusiast
Posts: 502
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

How to test if windows 32 or 64 bit

Post by jak64 »

Hello,
I searched the forum but couldn't find an answer to my question:

How to test in Purebasic if Windows is 32 or 64 bits?

thank you
Bitblazer
Enthusiast
Enthusiast
Posts: 733
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: How to test if windows 32 or 64 bit

Post by Bitblazer »

The simple method would be to check if a pointer uses 4 byte or 8 byte. Or use IsWow64Process. But this is just for simple cases and does not work if you run a win32 session on a win64 host :o
webpage - discord chat links -> purebasic GPT4All
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4637
Joined: Sun Apr 12, 2009 6:27 am

Re: How to test if windows 32 or 64 bit

Post by RASHAD »

Author: freak

Code: Select all

Prototype GetNativeSystemInfo(*lpSystemInfo.SYSTEM_INFO)

#PROCESSOR_ARCHITECTURE_AMD64 = 9
#PROCESSOR_ARCHITECTURE_IA64  = 6
#PROCESSOR_ARCHITECTURE_INTEL = 0
#PROCESSOR_ARCHITECTURE_UNKNOWN = $ffff


Procedure Is64bitOS()
  Protected kernel32, GetNativeSystemInfo.GetNativeSystemInfo
  Protected info.SYSTEM_INFO
  Protected Result = #False
 
  kernel32 = OpenLibrary(#PB_Any, "Kernel32.dll")
  If kernel32
    GetNativeSystemInfo = GetFunction(kernel32, "GetNativeSystemInfo")
   
    If GetNativeSystemInfo
      GetNativeSystemInfo(@info)
      If info\wProcessorArchitecture <> #PROCESSOR_ARCHITECTURE_INTEL ; x86
        Result = #True
      EndIf     
    EndIf
 
    CloseLibrary(kernel32)
  EndIf 

  ProcedureReturn Result
EndProcedure

Debug Is64bitOS()
Author: ts-soft

Code: Select all

Import ""
  GetNativeSystemInfo(*info)
EndImport

Procedure Is64bitOS()
  Protected Info.SYSTEM_INFO
  GetNativeSystemInfo(Info)
  If info\wProcessorArchitecture
    ProcedureReturn #True
  EndIf
EndProcedure

Debug Is64bitOS()
Egypt my love
jak64
Enthusiast
Enthusiast
Posts: 502
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: How to test if windows 32 or 64 bit

Post by jak64 »

Hello,
Thank you all for your responses
User avatar
jacdelad
Addict
Addict
Posts: 1437
Joined: Wed Feb 03, 2021 12:46 pm
Location: Planet Riesa
Contact:

Re: How to test if windows 32 or 64 bit

Post by jacdelad »

I use

Code: Select all

CompilerIf #PB_Compiler_Processor=#PB_Processor_x64
  Procedure Is32On64()
    ProcedureReturn 0  
  EndProcedure  
CompilerElse
  Import ""
    GetNativeSystemInfo(*temp)
  EndImport
  Procedure Is32On64()
    Protected temp.SYSTEM_INFO
    GetNativeSystemInfo(temp)
    Select temp\wProcessorArchitecture
      Case 6,9,12
        ProcedureReturn 1
    EndSelect
    ProcedureReturn 0
  EndProcedure
CompilerEndIf
PureBasic 6.04/XProfan X4a/Embarcadero RAD Studio 11/Perl 5.2/Python 3.10
Windows 11/Ryzen 5800X/32GB RAM/Radeon 7770 OC/3TB SSD/11TB HDD
Synology DS1821+/36GB RAM/130TB
Synology DS920+/20GB RAM/54TB
Synology DS916+ii/8GB RAM/12TB
BarryG
Addict
Addict
Posts: 3294
Joined: Thu Apr 18, 2019 8:17 am

Re: How to test if windows 32 or 64 bit

Post by BarryG »

There should be a native command to do this.
Bitblazer
Enthusiast
Enthusiast
Posts: 733
Joined: Mon Apr 10, 2017 6:17 pm
Location: Germany
Contact:

Re: How to test if windows 32 or 64 bit

Post by Bitblazer »

BarryG wrote: Wed May 18, 2022 9:52 am There should be a native command to do this.
Yes. But Fred is busy with the V6 release.

So - who does a "(system) environment" module?

I tried to cover the the linux part here. windows info and parsing the CPU-ID bitmask are easily done. Maybe driver and I/O interfaces should be added (network, serial, wlan, parallel? usb!). It would probably be easier to detect or use common system information tools and parse the output to create the module structures / Infos. CPU-Z, GPU-Z, hwinfo, AMD and nvidia tools.

Maybe the futuremark systeminfo but i don't know if their license allows it.

This would be a great starting point to collect lot of info for such a module: Heise - Systeminfo tools
webpage - discord chat links -> purebasic GPT4All
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: How to test if windows 32 or 64 bit

Post by Marc56us »

jak64 wrote: Wed May 18, 2022 12:07 am How to test in Purebasic if Windows is 32 or 64 bits?

Code: Select all

If GetEnvironmentVariable("CommonProgramFiles(x86)")
  Debug "This is a 64 bits version of Windows"
Else
  Debug "This is a 32 bits version of Windows"
EndIf
PS. Type SET in a Window CMD, you will have many information that can be used with GetEnvironmentVariable("")
:wink:
jak64
Enthusiast
Enthusiast
Posts: 502
Joined: Sat Aug 15, 2020 5:02 pm
Location: Ciboure (France)

Re: How to test if windows 32 or 64 bit

Post by jak64 »

Tank you Marc56us
Post Reply