locked
Determining current CPU architecture (x32 or x64)

    Question

  • G'day,

    I've got a data loading application in .net and I need to check various registry entries to ensure that reading excel documents works correctly.

    In x32 clients there is a registry entry - HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Access Connectivity Engine\Engines\Excel\TypeGuessRows
    In x64 clients there is a registry entry - HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Office\12.0\Access Connectivity Engine\Engines\Excel\TypeGuessRows

    At the moment I try one the if that causes an exception I read the other and thats just clunky. I really want to include some logic before trying to read these entries to do something like. 

    Select Case CPUArchitecture
      Case x32
        Read x32 Registry
      Case x64
        Read x64 Registry
    End select.

    How do I do this logic in .net?


    Jamie Clayton
    • Edited by Jamie Clayton Thursday, November 26, 2009 11:31 PM Order of sentance wrong
    Thursday, November 26, 2009 11:31 PM

Answers

All replies

  • Hi Jamie,

    Thanks for your post.

    Please reading this blog: http://weblogs.asp.net/dvravikanth/archive/2007/10/30/how-to-determine-computer-is-32-bit-or-64-bit.aspx

    "Check the following registry key(by opening regedit at command prompt)

    "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE"

    If the value of PROCESSOR_ARCHITECTURE is "x86" then you have a 32 bit version of Windows

    if the value of PROCESSOR_ARCHITECTURE is not "x86" then your machine is potentially a 64-Bit.

    Hongye Sun [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com

    "

     
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, November 27, 2009 9:05 AM
  • you can also check IntPtr.Size if its 4 its a 32 bit process, if its 8 its a 64 bit process.
    Friday, November 27, 2009 2:58 PM
  • Hi,

    Is this issue resolved? Thanks.

    Hongye Sun [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, December 03, 2009 5:30 PM

  • "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\PROCESSOR_ARCHITECTURE"

    If the value of PROCESSOR_ARCHITECTURE is "x86" then you have a 32 bit version of Windows

    if the value of PROCESSOR_ARCHITECTURE is not "x86" then your machine is potentially a 64-Bit.



    Hongye,

    I've tested this against Windows 7x86, Windows Vistax86, Windows XPx86 and the registry contains "x86". Excellent.
    Windows Server 2008 R2 x64 and a Hyper V VM on that machine of Windows Server 2008 show "AMD64" which is matches your statement but the CPU is an Intell one, which is a little confussing.  I can however use the =x86 and !=x86 as logic in an application.  Thanks.

    I'm really looking forward to Office 2010 x64 support and the implicit driver support so my .net applications can finally run in x64 mode!  Finally x86 and x64 .net applications that leverage MS Office data.
    Jamie Clayton
    Thursday, December 17, 2009 9:52 PM
  • Hongye,

    Yes the problem is resolved, I didn't see my Live Messenger notification till today.
    Jamie Clayton
    Thursday, December 17, 2009 9:54 PM
  • Hongye,

    Yes the problem is resolved, I didn't see my Live Messenger notification till today.
    Jamie Clayton
    Wouldn't you use Environment.Is64BitOperatingSystem?
    Wednesday, December 28, 2011 12:33 AM
  • Hi PaulPav,

     this method available only in .net 4.0.

    You have to be clear whether you need OS or CPU architecture, because even having x64 machine architecture, you still able to use 32 bit OS. Considering machine architecture IntPtr.Size approach works fine, but when it comes to OS architecture bear in mind the following:

    x86 machine - 32 bit OS
    x64 machine - either 64 bit OS or 32 bit OS. You have to check whether IsWow64Process method exist and use it then to determine whether process is running under WOW64.


    Truly yours, Marat
    Friday, February 03, 2012 1:05 AM