Determine Windows Architecture (32 bit / 64bit)?

BlitzMax Forums/BlitzMax Programming/Determine Windows Architecture (32 bit / 64bit)?

therevills(Posted 2016) [#1]
Hi All,

I'm trying to determine if Windows is 32bit or 64bit. This is what I've got so far:



I'm running on Windows 8.1 64bit, but this returns:
GetWindowsVersionString = Windows 8
GetWindowsArchitecture  = 32bit


I believe this is because GetSystemInfo returns what the application is compiled for not the underlying OS.

Any clues?

Cheers,
Steve


Brucey(Posted 2016) [#2]
https://support.microsoft.com/en-gb/kb/556009

Note the the examples provided on the page have typos, so you'll need to use some common sense to work out the right keys, etc ;-)


therevills(Posted 2016) [#3]
Thanks for replying Brucey, I might have a different solution by using GetNativeSystemInfo, the clue was on this page:

https://msdn.microsoft.com/en-au/library/windows/desktop/ms724381(v=vs.85).aspx

To retrieve accurate information for an application running on WOW64, call the GetNativeSystemInfo function.




Now the output on Windows 8.1 64bit returns::
GetWindowsVersionString      = Windows 8
GetWindowsArchitecture       = 32bit
GetWindowsNativeArchitecture = 64bit

On Windows XP 32bit:
GetWindowsVersionString      = Windows XP
GetWindowsArchitecture       = 32bit
GetWindowsNativeArchitecture = 32bit

On Windows 10 64bit:
GetWindowsVersionString      = Windows 8
GetWindowsArchitecture       = 32bit
GetWindowsNativeArchitecture = 64bit

(Yep Win10 reports as Win8...)

On Windows 7 32bit:
GetWindowsVersionString      = Windows 7
GetWindowsArchitecture       = 32bit
GetWindowsNativeArchitecture = 32bit


On Windows 7 64bit:
GetWindowsVersionString      = Windows 7
GetWindowsArchitecture       = 32bit
GetWindowsNativeArchitecture = 64bit

What do you reckon?

Steve


Hezkore(Posted 2016) [#4]
This has worked for me in the past.
Though that would be processor, which won't mean Windows is the same version.
Local Processor:String = getenv_("PROCESSOR_ARCHITEW6432")
Select Right(Processor, 2)
	Case "32" Processor = "win32"
	Case "86" Processor = "win32"
	Default Processor = "win64"
EndSelect
Print Processor



therevills(Posted 2016) [#5]
Thanks Hezkore - yeah really need the OS version.

I've now tested the above code on 5 PCs and it works pretty well using GetNativeSystemInfo.


Fielder(Posted 2016) [#6]
to identify windows 8.1/10 you can check this folder: configuration

If FileType(windowsfolder+"\system32\configuration")>0 os$="Windows8.1/10"


to exclude windows 8.1 and identify windows 10 you can check this file: WPR.EXE

if FileType(windowsfolder+"\sysnative\WPR.EXE")>0 os$="Windows 10"


retrieve Windows 10 (DECLARED) BUILD:

realbuild$=Upper(String (reg_getvalue(HKEY_CURRENT_USER,"SOFTWARE\Microsoft\Internet Explorer\Main","EdgeSwitchingOSBuildNumber"))[..9])


to retrieve the INSIDER BUILD (NOT DECLARED TO APPLICATIONS):

insiderbuild=lower(String (reg_getvalue(HKEY_LOCAL_MACHINE,"SOFTWARE\Microsoft\Windows NT\CurrentVersion","BuildLab")))



BlitzSupport(Posted 2016) [#7]
You should be able to use GetSystemInfo with this structure to determine 32-versus-64 bit build: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724958%28v=vs.85%29.aspx

And if you update this to include more recent versions of Windows, you can combine the results:

Windows version detection

List of version numbers/OSes in table further down:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms724833%28v=vs.85%29.aspx

Bear in mind some users will be running a 64-bit processor with a 32-bit OS!


xlsior(Posted 2016) [#8]
FWIW, Windows also stores a bunch of information in the registry at HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion , although it's not always correct: I've seen a computer that had been upgraded from Windows 8 to Windows 10 still claim to be windows 8 in the registry.


grable(Posted 2016) [#9]
There is also IsWow64Process, present since XP-SP2.

EDIT: You would use it like this..
Function IsWow64Process:Int()
	Extern "Win32"
		Function GetCurrentProcess:Int()
		Function FreeLibrary( lib:Int)
	EndExtern
	Local lib:Int = LoadLibraryA("kernel32.dll")
	Local IsWow64Process_:Int( handle:Int, result:Int Var) = GetProcAddress( lib, "IsWow64Process")
	If Not IsWow64Process_ Then Return False
	Local result:Int = False
	IsWow64Process_( GetCurrentProcess(), result)
	FreeLibrary(lib)
	Return result
EndFunction



therevills(Posted 2016) [#10]
Thanks all.

@James - GetSystemInfo will return the Architecture of the build not the OS, see my #3 post.

@grable - yeah I was reading about IsWow64Process but was unsure how to access it in BlitzMax, thanks for the example.