Determing 32 or 64 bit
Posted: Sun Aug 24, 2008 10:07 pm
In there a way with Purebaic to determine if the OS is 32 bit or 64 bit?
http://www.purebasic.com
https://www.purebasic.fr/english/
Keyname: PROCESSOR_ARCHITECTUREHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
This isn't the right way to gomilan1612 wrote:This information is stored by Windows in this registry key:Keyname: PROCESSOR_ARCHITECTUREHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
Code: Select all
Debug GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
It is more or less the same - all environment variables are stored in this registry keyts-soft wrote:This isn't the right way to gomilan1612 wrote:This information is stored by Windows in this registry key:Keyname: PROCESSOR_ARCHITECTUREHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
In 32-Bit PB Programs come "x86" and in 64-Bit PB-Programs come "AMD64"Code: Select all
Debug GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
Code: Select all
EnableExplicit
Procedure.s Reg_ReadString(topKey.l, KeyName.s, ValueName.s)
Protected Result.s, hKey.l, lpData.s = Space(255), lpcbData.l, Error.l
lpcbData = (255 * SizeOf(Character)) + 1
If Right(KeyName, 1) = "\" : KeyName = Left(KeyName, Len(KeyName) - 1) : EndIf
Error = RegOpenKeyEx_(topKey, @KeyName, 0, #KEY_ALL_ACCESS, @hKey)
If Error = #ERROR_SUCCESS
Error = RegQueryValueEx_(hKey, @ValueName, 0, 0, @lpData, @lpcbData)
If Error = #ERROR_SUCCESS
Result = lpData
Else
lpData.s = Space(lpcbData)
Error = RegQueryValueEx_(hKey, @ValueName, 0, 0, @lpData, @lpcbData)
If Error = #ERROR_SUCCESS
Result = lpData
Else
Result = ""
EndIf
EndIf
EndIf
If hKey : RegCloseKey_(hKey) : EndIf
ProcedureReturn Result
EndProcedure
Debug Reg_ReadString(#HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "PROCESSOR_ARCHITECTURE")
Debug GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
Yes! Is the same result on intel-cpuSFSxOI wrote:Does it still return "AMD64" on intel chipsets and processors?
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()
Code: Select all
Import ""
GetNativeSystemInfo(*info)
EndImport
Procedure Is64bitOS()
Protected Info.SYSTEM_INFO
GetNativeSystemInfo(Info)
If info\wProcessorArchitecture
ProcedureReturn #True
EndIf
EndProcedure
Debug Is64bitOS()
You can also try this:SFSxOI wrote:Nice examples everyone, thanks for the help.
Code: Select all
Procedure.l IsWin64() ;Tell us if the OS is x64 or not.
*Is64 = 0
If OpenLibrary(0,"KERNEL32.DLL")
*F = GetFunction(0,"IsWow64Process")
If *F
CallFunctionFast(*F,GetCurrentProcess_(), @*Is64)
EndIf
CloseLibrary(0)
EndIf
If *Is64>0
ProcedureReturn 1 ; True
Else
ProcedureReturn 0 ; False
EndIf
EndProcedure
Debug IsWin64()
On my 64-bit PC, it returns "x86" because I use the 32-bit version of PureBasic.ts-soft wrote:In 32-Bit PB Programs come "x86" and in 64-Bit PB-Programs come "AMD64"Code: Select all
Debug GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
ts-soft posted the same thing if you look at the quote.PB wrote:On my 64-bit PC, it returns "x86" because I use the 32-bit version of PureBasic.ts-soft wrote:In 32-Bit PB Programs come "x86" and in 64-Bit PB-Programs come "AMD64"Code: Select all
Debug GetEnvironmentVariable("PROCESSOR_ARCHITECTURE")
Just something to be aware of... it's therefore not reliable to use for testing.