none
How Can I Count how many CPU cores a PC Has like what is shown in Windows System using VB.net RRS feed

  • Question

  • I would like to display how many CPU Cores my PC has like Windows System. I can get all the the other information about the processor. I don't know where I can get the Core information. I searched the registry, but no luck.

    Windows System

    Processor            Intel(R) Core(TM) i3-4170 CPU @ 3.70GHz, 3700 Mhz, 2 Core(s), 4 Logical Processor(s).



    • Edited by VBShaper Monday, June 4, 2018 9:53 PM
    Monday, June 4, 2018 9:51 PM

Answers

  • Hi VBShaper,

    If you want to get the numbers of the CPU cores, you can take the following code. Please add system.management.dll to your project.

    Dim coreCount As Integer = 0
    
            For Each item In New System.Management.ManagementObjectSearcher("Select * from Win32_Processor").[Get]()
                coreCount += Integer.Parse(item("NumberOfCores").ToString())
            Next
    
            Console.WriteLine("Number Of Cores: {0}", coreCount)

    You can also take a look the following thread, it is C#, but you can use any code converter to convert code to vb.net.

    https://stackoverflow.com/questions/1542213/how-to-find-the-number-of-cpu-cores-via-net-c

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Cor Ligthert Tuesday, June 5, 2018 10:06 AM
    • Marked as answer by VBShaper Tuesday, June 5, 2018 6:01 PM
    Tuesday, June 5, 2018 3:01 AM
    Moderator

All replies

  • You can use WMI with Win32_Processor (NumberOfCores)

    • Edited by Castorix31 Monday, June 4, 2018 10:55 PM
    • Proposed as answer by Cor Ligthert Tuesday, June 5, 2018 10:06 AM
    Monday, June 4, 2018 10:54 PM
  • Hi VBShaper,

    If you want to get the numbers of the CPU cores, you can take the following code. Please add system.management.dll to your project.

    Dim coreCount As Integer = 0
    
            For Each item In New System.Management.ManagementObjectSearcher("Select * from Win32_Processor").[Get]()
                coreCount += Integer.Parse(item("NumberOfCores").ToString())
            Next
    
            Console.WriteLine("Number Of Cores: {0}", coreCount)

    You can also take a look the following thread, it is C#, but you can use any code converter to convert code to vb.net.

    https://stackoverflow.com/questions/1542213/how-to-find-the-number-of-cpu-cores-via-net-c

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Cor Ligthert Tuesday, June 5, 2018 10:06 AM
    • Marked as answer by VBShaper Tuesday, June 5, 2018 6:01 PM
    Tuesday, June 5, 2018 3:01 AM
    Moderator
  • Check this value too: System.Environment.ProcessorCount.


    Tuesday, June 5, 2018 5:40 AM
  • Thank you Cor Lighter. That worked perfectly and Thank you all for your answers.
    Tuesday, June 5, 2018 6:03 PM