Check if Windows or your Program is in 64-bit or 32-bit Mode using VB.NET and Higher

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 4.00 out of 5)
 

A while back I made a simple post on using WMI (Windows Management Instrumentaion) to check if the operating system your program was running on was 32-bit or 64-bit. The main problem with that method is its not supported on Windows XP and doesn’t tell you what mode your application is running in. I made a small example with different methods that should be near fool proof. I have 4 methods of checking if your application is 32 bit (x86) or 64 bit (x64 or AMD64 which is the code name). I also have 5 methods of checking what mode the operating system is running in. If you still can’t pin down whether your application/operating system is 32 or 64 bit then I don’t know what to tell you. BTW here is a link to the earlier post I made on how to easily check if the operating system is 32-bit or 64-bit using WMI, which applications running on Vista or Windows 7 can use just fine.

Image of example application

There is to much code in the example I made to post here. You should definitely download it and check it out. It was made with VB 2005 but the codes will work in VB.NET 2002,.NET 2003, Visual Basic 2008, and Visual Basic.NET 2010 as well. So I will just highlight a couple ways to determine your application and os mode.


The code below grabs a string from a registry key and examines the text. This  is pretty much a fool proof way of whether your cpu is running on a x86 or x64 operating system. All you need to do is check a specific key in the registry like below…

        Dim cpuID As String = _
            My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\HARDWARE\DESCRIPTION\System\CentralProcessor\0", _
                "Identifier", "n/a")
        '
        'Get all chars from the beginning of the string until the first space is detected.
        cpuID = cpuID.Substring(0, cpuID.IndexOf(" "))

        MsgBox(cpuID)

If the key has x86 then its 32bit. If the key has AMD 64 or Intel64 then Windows is 64 bit. You can also check the registry key’s text to see if it contains AMD64 or Intel64. Of course if it contains x86 then the os is 32-bit and its 64-bit if it contains AMD64 or Intel64.

        'You can also check the registry string in this way.
        If LCase(cpuID).Contains("amd64") OrElse LCase(cpuID).Contains("intel64") Then

            MsgBox("It Is 64 Bit!")

        End If

I also want to show a simple way of checking if your application is running in 32 bit or 64 bit mode. You can simply check the size of IntPtr. If the pointer size is 4 bytes then its 32 bit. If its 8 bytes then its 64 Bit. This code simply checks if the size is higher than 4 or not. If its higher than 4 then its 64 bit. Otherwise its 32 bit. Remember, this method is the mode at the application level and not the platform level.

        'Basically if the Integer Pointer size is 4 then its 32 Bit and 8 is 64 Bit
        If IntPtr.Size > 4 Then

            MsgBox("64 Bit!")

        Else

            MsgBox("32 Bit!")

        End If

This post was mainly to give you an overview of a couple methods I used in the example program I made. The best thing would be for you to download the example and check out all of the methods I’ve come up with (or found out about).

I might add more to this little article in the future. That’s all for now. Have fun!

Jason

One thought on “Check if Windows or your Program is in 64-bit or 32-bit Mode using VB.NET and Higher

  1. Chris Tschantz

    I found this very useful thanks.

    By the way… even if your running VS 2010 or above you may not always use the Environment.Is64BitOperatingSystem property.

    If you have to have the compiler set-up for .Net Framework 4 and above for it to work. In my particular case i compile my applications in .Net Framework 3.5 since barely any systems in my Organization have .Net Framework 4 installed.

    Thanks again!

    Reply

Leave a Reply