Tag Archives: system.environment

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(" "))


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!")


            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!


Find out how many CPU’s/Processors/Cores the computer has installed using VB.NET and Higher

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

Its actually very easy with Visual Basic.NET VB 2008, VB.NET 2010, 2013, and Higher to detect the cpu or core count for the computer. Below is the very simple way to do it which will return the total number of logical processors installed in the computer…

        'This works for Visual Basic 2005 and Higher.
        'The code we want is under the System.Environment Namespace and is the ProcessorCount

What if you want to get the CPU/Processor/Core count with Visual Basic.NET 2002 or 2003?

Well, .NET version 1.1 and older does not have the ProcessorCount property like version 2.0 of the .NET Framework. But that doesn’t mean it can’t be done. Its actually not to awfully hard to do. Below is a way to do it using the Windows system Registry…

        'The registry path to get the info we are wanting.
        Dim str As String = "HARDWARE\DESCRIPTION\System\CentralProcessor"
        'Returns how many SubKeys are under “CentralProcessor”. The subKey count under this key
        '=’s the‘total cpu’s your system has installed. Of course, 90% or so will only have 1x
        'subkey denoting a ‘single cpu system. My system happens to return 2x subkeys since I
        'have a Dual Core system.
        Dim cpuCount As Integer = My.Computer.Registry.LocalMachine.OpenSubKey(str, False).SubKeyCount


The Messagebox will then throw a Dialog with the total number of cpu’s/core’s on the current computer. I do not know though if this works on all Windows operating systems.

You can also use the Windows Management Instrumentation (WMI) and get the total instances of the class.

Below is a simple way to use WMI to return the computers CPU/Core Count…

        'Create a Instrument Class and Object.
        Dim wmiClass As New System.Management.ManagementClass
        Dim wmiObject As New System.Management.ManagementObject
        'Set the PAth to “Win32_Processor” which is where we want to get info.
        wmiClass.Path.RelativePath = "Win32_Processor"
        'Last of all, just check how many instances is available and that will be your cpu/core count.

Executing the code above will tell you how many cpus are on the computer since there is a class instance for each CPU/processor/core on the current computer.

Take care 🙂


Revised: 2015

Get the Operating System: Name, Platform, Version, and Service Pack using VB.NET 2008 and higher

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)

This will return the Windows Operating System Name, Platform, and Version using the MY interface under VB 2008, Visual Basic 2010, and 2013. Then from the System.Environment class it will get the operating systems installed Service Pack, and then the entire OS info in one string value.

'This will throw 5x messageboxes with the FullName of the Installed Windows, along with
'the OS Platform, OS Version, the service pack installed, and then a message show all
'of the information about windows. that your program is running on. This works with VB 2005,
'Visual Basic.NET 2008, and Visual Basic 2010

Revised: 2015