Results 1 to 6 of 6

Thread: [2005] 32-Bit Vs 64-Bit [RESOLVED]

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    20

    [2005] 32-Bit Vs 64-Bit [RESOLVED]

    Is there a way to programatically determine if the OS Architecture is 32-bit or 64 -bit?
    Last edited by rcatiggay; Oct 5th, 2007 at 01:08 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: [2005] 32-Bit Vs 64-Bit

    I don't think there's actually a managed property or method for that anywhere. This should do the trick, although I haven't actually tested it on a 64-bit Windows install.
    vb.net Code:
    1. <Runtime.InteropServices.DllImport("kernel32")> _
    2. Private Shared Function IsWow64Process(ByVal hProcess As IntPtr, _
    3.                                        ByRef wow64Prcess As Boolean) As Boolean
    4. End Function
    5.  
    6. Private Function IsWow64() As Boolean
    7.     Dim wow64 As Boolean
    8.  
    9.     IsWow64Process(Process.GetCurrentProcess().Handle, wow64)
    10.  
    11.     Return wow64
    12. End Function
    Note that this will tell you if the current process is a 32-bit application running on 64-bit Windows. If it's a native 64-bit application then you'd already know that and it couldn't run on 32-bit platforms.

  3. #3
    Frenzied Member
    Join Date
    Mar 2005
    Location
    Sector 001
    Posts
    1,577

    Re: [2005] 32-Bit Vs 64-Bit

    Code:
    MessageBox.Show(System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE"))
    should work too but I only have 32bit XP and can't test it. Wouldn't the IntPtr size be informative too? It shows 32 here, which is to be expected in my case.
    VB 2005, Win Xp Pro sp2

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: [2005] 32-Bit Vs 64-Bit

    Quote Originally Posted by Half
    Code:
    MessageBox.Show(System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE"))
    should work too but I only have 32bit XP and can't test it. Wouldn't the IntPtr size be informative too? It shows 32 here, which is to be expected in my case.
    I was under the impression that that code would provide information about the processor itself rather than the OS, but I just ran it on 32-bit Windows running on a 64-bit processor and got "x86" as the result. I have also read suggestions for using the fact that the size of an IntPtr will be 4 on 32-bit systems and 8 on 64-bit systems, which you would exploit like so:
    vb.net Code:
    1. Runtime.InteropServices.Marshal.SizeOf(GetType(IntPtr))

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 2005
    Posts
    20

    Re: [2005] 32-Bit Vs 64-Bit

    Thanks to all I got it working.

  6. #6
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: [2005] 32-Bit Vs 64-Bit [RESOLVED]

    Sorry to drag this old thread up but for anyone that finds it via a search I thought it would be worth mentioning that the IsWow64Process API that JMC mentioned does not exist on Windows XP unless SP2 is installed (and obviously also doesnt exist on Windows 2000) so that code will crash on a pre SP2 XP machine. After looking at the code that Microsoft use in the .NET 4.0 property Is64BitProcess, I've found that you can use another API (well a combination of a few) to check for the existence of a method in an unmanaged DLL. As there seem to be a few threads on this subject, all without a straight forward answer, I think I'll stick something in the codebank that is an absolutely fool proof way of finding out if your code is running on a 64 bit OS, unless someone else already has

    EDIT: See this thread: http://www.vbforums.com/showthread.php?t=613889
    Last edited by chris128; May 6th, 2010 at 03:03 PM.
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width