Can someone check this for me on 64 bit?

Everything else that doesn't fall into one of the other PB categories.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Can someone check this for me on 64 bit?

Post 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 :)
Last edited by SFSxOI on Sun Mar 11, 2012 1:26 am, edited 5 times in total.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Can someone check this for me on 64 bit?

Post 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
 
"Have you tried turning it off and on again ?"
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Can someone check this for me on 64 bit?

Post by ts-soft »

Is always #True on my Windows 7 64-Bit
PB 4.61b x86 and x64
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: Can someone check this for me on 64 bit?

Post 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 :)
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Can someone check this for me on 64 bit?

Post 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
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: Can someone check this for me on 64 bit?

Post by SFSxOI »

IdeasVacuum, the registry check isn't a reliable check for my purpose and requirements.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Can someone check this for me on 64 bit?

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Can someone check this for me on 64 bit?

Post 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 :wink:
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: Can someone check this for me on 64 bit?

Post 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.
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Can someone check this for me on 64 bit?

Post by IdeasVacuum »

....Now that's a good explanation!
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Can someone check this for me on 64 bit?

Post 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!
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Can someone check this for me on 64 bit?

Post 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.
"Have you tried turning it off and on again ?"
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Can someone check this for me on 64 bit?

Post by IdeasVacuum »

...but the SizeOf() issue, as I understand it, is if your app is 32bit and the OS is 64bit.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: Can someone check this for me on 64 bit?

Post by Tenaja »

If it is an issue, then it is a PB bug, because as Luis said, it is a constant by definition.
User avatar
luis
Addict
Addict
Posts: 3895
Joined: Wed Aug 31, 2005 11:09 pm
Location: Italy

Re: Can someone check this for me on 64 bit?

Post 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.
"Have you tried turning it off and on again ?"
Post Reply