Page 1 of 2
Can someone check this for me on 64 bit?
Posted: Thu Mar 08, 2012 4:24 pm
by SFSxOI
The MSDN page for "IsWow64Process" says this:
"Note that this technique is not a reliable way to detect whether the operating system is a 64-bit version of Windows because the Kernel32.dll in current versions of 32-bit Windows also contains this function."
This means that "IsWow64Process" alone cannot differentiate between a 32bit process on 32bit Windows and a 64bit process on 64bit Windows because 'IsWow64Process' returns false for both conditions. However, it does not mean that "IsWow64Process" can't be used to determine the actual OS bit'ness (not the process bit'ness) and it just needs a little help.
So, I can't get to a 64 bit windows system right now and if someone could check this on 64 bit windows it would help as I wanted to check this in PB.
Code: Select all
; based upon the code at:
; http://1code.codeplex.com/SourceControl/changeset/view/39074#842774
; http://1code.codeplex.com/SourceControl/changeset/view/39074#842775
; both samples written by Jialiang Ge, MSFT, I believe
Prototype PIsWow64Process(hProcess, out_Wow64Process)
Global IsWow64Process.PIsWow64Process
Lib_Kernel32 = OpenLibrary(#PB_Any,"Kernel32.dll")
If IsLibrary(Lib_Kernel32)
IsWow64Process.PIsWow64Process=GetFunction(Lib_Kernel32,"IsWow64Process")
EndIf
; This procedure returns true if the operating system its self, not the process, is 64-bit otherwise it returns false.
; for Windows Vista (and WinXP Pro 64bit with SP2) and above - tested so far on Windows 7 x86 - PB 4.60
Procedure.b Is64BitOS()
If SizeOf(Integer) = 8 ; if int = 8 then 64 bit - 64 bit programs run only on Win 64 and if 64 bit program is running clearly its 64 bit OS
ProcedureReturn #True ;;;; 64 bit programs run only on Win64
Else ; 32 bit processes can run on 64 bit windows so what if its a 32 bit process running in 64 bit windows and we still need to determine the OS bit'ness
; this checks for that and returns #False is the OS its self is 32 bit, #True if OS its self is 64 bit
f64bitOS.b = #False
ProcedureReturn ((IsWow64Process(GetCurrentProcess_(), @f64bitOS)) And f64bitOS)
EndIf
EndProcedure
Debug Is64BitOS()
Too bad though .Net is such a pain to access via PB, if at all, because .Net has a 'Is64BitOperatingSystem' function which tells you.
Anyway, if someone could check it that would be great, Thanks

Re: Can someone check this for me on 64 bit?
Posted: Thu Mar 08, 2012 4:38 pm
by luis
Returns 1 on Win7 x64 (both 32/64 bit PB executables)
This is my routine for the same thing, seem similar to yours.
Code: Select all
Procedure.i sgl_Is64BitOS()
; [DESC]
; Check if the OS under which the program is running is a 64 bit OS.
;
; [RETURN]
; 1 for 64 bit OS, else 0.
Protected Is64BitOS = 0
Protected hDLL, IsWow64Process_
If SizeOf(Integer) = 8
Is64BitOS = 1 ; this is a 64 bit exe
Else
hDll = OpenLibrary(#PB_Any,"kernel32.dll")
m_ASSERT(hDLL)
If hDll
IsWow64Process_ = GetFunction(hDll,"IsWow64Process")
If IsWow64Process_
CallFunctionFast(IsWow64Process_, GetCurrentProcess_(), @Is64BitOS)
EndIf
CloseLibrary(hDll)
EndIf
EndIf
ProcedureReturn Is64BitOS
EndProcedure
Re: Can someone check this for me on 64 bit?
Posted: Thu Mar 08, 2012 4:40 pm
by ts-soft
Is always #True on my Windows 7 64-Bit
PB 4.61b x86 and x64
Re: Can someone check this for me on 64 bit?
Posted: Thu Mar 08, 2012 4:56 pm
by SFSxOI
Looks like it works then. It should return true on 64 bit windows even if the process is 32 bit, and false on 32 bit windows (which it does here on Windows 7 x86).
Thanks folks

Re: Can someone check this for me on 64 bit?
Posted: Thu Mar 08, 2012 10:50 pm
by IdeasVacuum
Via the Registry:
Code: Select all
Procedure.s OSbits()
;-------------------
lpftLastWriteTime.FILETIME
lpName.s = ""
sKeyName.s = "Software\Wow6432Node"
sOSbits.s = "64"
sSubKey.s = ""
iIndex.i = 1
hKey.i = 0
GetHandle.l = 0
If Left(sKeyName, 1) = ""
sKeyName = Right(sKeyName, Len(sKeyName) - 1)
EndIf
GetHandle = RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, sKeyName, 0, #KEY_ALL_ACCESS, @hKey)
If GetHandle = #ERROR_SUCCESS
lpcbName = 255
lpName = Space(255)
GetHandle = RegEnumKeyEx_(hKey, iIndex, @lpName, @lpcbName, 0, 0, 0, @lpftLastWriteTime)
If GetHandle = #ERROR_SUCCESS : sSubKey = Left(lpName, lpcbName) : EndIf
EndIf
RegCloseKey_(hKey)
If sSubKey = "" : sOSbits = "32" : EndIf
ProcedureReturn sOSbits
EndProcedure
Re: Can someone check this for me on 64 bit?
Posted: Thu Mar 08, 2012 11:54 pm
by SFSxOI
IdeasVacuum, the registry check isn't a reliable check for my purpose and requirements.
Re: Can someone check this for me on 64 bit?
Posted: Sat Mar 10, 2012 7:13 pm
by IdeasVacuum
Given that other people will be looking for the same functionality, I think you need to explain why the registry method isn't a reliable check in this instance. It's possible for an app to create that key, but highly unlikely (unless malicious) - I have never had an issue using this method.
Re: Can someone check this for me on 64 bit?
Posted: Sat Mar 10, 2012 7:30 pm
by ts-soft
IdeasVacuum wrote:I have never had an issue using this method.
Without Admin-Privilege comes always 32-Bit! I think this is not so usefull

Re: Can someone check this for me on 64 bit?
Posted: Sat Mar 10, 2012 10:51 pm
by SFSxOI
IdeasVacuum wrote:Given that other people will be looking for the same functionality, I think you need to explain why the registry method isn't a reliable check in this instance. It's possible for an app to create that key, but highly unlikely (unless malicious) - I have never had an issue using this method.
Well, I didn't think It needed an explaination, its a simple check for OS bit'ness, but ....but 'cause .... some 32 bit code trying to access the 'Wow6432Node' registry key entry on a 64 bit windows platform can cause an endless recursive loop due to registry redirection, and "I have never had an issue using this method" type of thing is not good enough for a government contract certification of methods. So I needed something that would avoid any bad possibilities, the check method I proposed here is much safer and doesn't need registry access, plus I can get this method certified for use where the registry access method to check can't be certified for use. Then there is the admin privilage thing. This method prevents all that and is more suitable especially when this method is safer to use.
Re: Can someone check this for me on 64 bit?
Posted: Fri Mar 16, 2012 7:52 am
by IdeasVacuum
....Now that's a good explanation!
Re: Can someone check this for me on 64 bit?
Posted: Fri Mar 16, 2012 3:44 pm
by IdeasVacuum
....I just noticed the first quick test, SizeOf(Integer). This is deemed unreliable at runtime (via exe) if your app is 32bit running on a 64bit OS (Google search).
The test for IsWow64Process via the kernel32.dll on the other hand seems to be very popular. However, that is a System DLL of course and could be afforded more protection on Windows8, perhaps requiring the User to be Admin or pass some other security test, which would reduce it's effectiveness.
There is another good idea out there - In your installation package for your 32bit app, include a small 64bit exe. Your 32bit app can attempt to run the 64bit one on start-up - if the OS is 32 bit, that will fail, thus confirming 32 bits.
Edit: By the way, I did have an options panel in my installer where the User would select precisely which OS they were on. I was surprised to find that many people got this wrong!
Re: Can someone check this for me on 64 bit?
Posted: Fri Mar 16, 2012 6:13 pm
by luis
IdeasVacuum wrote:....I just noticed the first quick test, SizeOf(Integer). This is deemed unreliable at runtime (via exe) if your app is 32bit running on a 64bit OS (Google search).
The test in the procedures in this thread is only here to check if the OS is 64 bit (since it's executing a 64 bit exe it is) to avoid unnecessary further testing)
And SizeOf is processed by the compiler, not at runtime. It causes the compiler to generate an exe with a "4" instead of SizeOf(integer) for the 32 bit version of the compiler, and "8" for the 64 bit version.
So it cannot be unreliable by definition.
a = SizeOf(Integer)
is translated to:
MOV dword [v_a],4
under x86.
Running that under x64 cannot change this.
If the code is instead
MOV qword [v_a],8
then your exe can only be a 64 bit exe, and if it is running then the OS can only be a 64 bit OS.
Re: Can someone check this for me on 64 bit?
Posted: Fri Mar 16, 2012 11:17 pm
by IdeasVacuum
...but the SizeOf() issue, as I understand it, is if your app is 32bit and the OS is 64bit.
Re: Can someone check this for me on 64 bit?
Posted: Sat Mar 17, 2012 12:08 am
by Tenaja
If it is an issue, then it is a PB bug, because as Luis said, it is a constant by definition.
Re: Can someone check this for me on 64 bit?
Posted: Sat Mar 17, 2012 1:02 am
by luis
IdeasVacuum wrote:...but the SizeOf() issue, as I understand it, is if your app is 32bit and the OS is 64bit.
If your app is 32bit sizeof(integer) is 4. Why is that an issue with the code proposed here ?
Code: Select all
If SizeOf(Integer) = 8
Is64BitOS = 1 ; this is a 64 bit exe (and the OS is 64 bit too)
Else
.... check using IsWow64Process because it can be a 32 or 64 bit OS
Obviously checking sizeof(integer) to see if it's 8 under a 64bit OS when your exe is 32 bit doesn't make sense. That wouldn't be an issue, simply a wrong test. No one did that here.
If you want to link the google result you were referring to... because I don't understand.