40

I am trying to retrieve the Number of CPUs and Cores per CPU using Command Prompt. I have executed the following command:

wmic cpu get NumberOfCores, NumberOfLogicalProcessors/Format:List

I get this error: wmic' is not recognized as an internal or external command, operable program or batch file

I am executing this on a Windows Server 2008 R2 machine. I believe the 'wmic' command is compatible on this windows.

The directory I am running the command promt from is 'C:\Windows>

Any advice please?

NeronLeVelu
  • 9,372
  • 1
  • 21
  • 41
Mustafa
  • 665
  • 1
  • 7
  • 15
  • 2
    Is `C:\Windows\System32\Wbem` on your path, and is there actually a file `C:\Windows\System32\wbem\WMIC.exe`? – Michael Burr Apr 07 '14 at 17:41
  • 6
    if you need the count of physical CPUs, use `wmic computersystem get numberofprocessors` – Stephan Apr 07 '14 at 18:16
  • 1
    @MichaelBurr I just have literally 'C:\Windows>wmic cpu get NumberOfCores, NumberOfLogicalProcessors/Format:List There is a filepath that leads to C:\Windows\System32\wbem\WMIC.exe – Mustafa Apr 08 '14 at 11:22
  • @MichaelBurr I changed the directory to C:\Windows\System32\Wbem and now the command works. Thanks! Do you want to post as answer so I can accept? – Mustafa Apr 08 '14 at 11:29
  • To include even the CPU information you got to be running `wmic cpu get SocketDesignation, NumberOfCores, NumberOfLogicalProcessors /Format:List` – RBT Mar 21 '17 at 13:00

5 Answers5

84

You can use the environment variable NUMBER_OF_PROCESSORS for the total number of processors:

echo %NUMBER_OF_PROCESSORS%
R1tschY
  • 2,484
  • 22
  • 28
  • Does this environment variable exist on all versions of Windows??? That is incredibly useful. Are you aware of it's OS version compatibility? – rubynorails Jan 29 '16 at 16:12
  • I only found that it was introduced in Windows 2000/NT. I guess it exists in every Windows desktop and server version after Windows 2000. – R1tschY Jan 30 '16 at 17:26
  • 8
    This delivers the total Number of Cores but not the number of CPUs. – Magier Mar 23 '16 at 13:37
  • I confirmed that this shows the total number of cores across all sockets – northben Jul 22 '16 at 13:15
  • This is not total number of cores in my hp Windows 10 Pro desktop pc. It is number of Logical processors. My pc has 6 cores and 12 processors so it gives 12. Is anyone knows how can I get that number 6 (number of cores)? – Halil İbrahim Oymacı Mar 13 '20 at 07:45
  • This is not working windows or linux... I have received empty in windows and linux both. Why it is ? – Chaminda Bandara Aug 09 '20 at 10:54
8

You can also enter msinfo32 into the command line.

It will bring up all your system information. Then, in the find box, just enter processor and it will show you your cores and logical processors for each CPU. I found this way to be easiest.

RBT
  • 18,275
  • 13
  • 127
  • 181
DomainsFeatured
  • 1,304
  • 1
  • 19
  • 32
5

Based upon your comments - your path statement has been changed/is incorrect or the path variable is being incorrectly used for another purpose.

foxidrive
  • 37,659
  • 8
  • 47
  • 67
2

If you want to find how many processors (or CPUs) a machine has the same way %NUMBER_OF_PROCESSORS% shows you the number of cores, save the following script in a batch file, for example, GetNumberOfCores.cmd:

@echo off
for /f "tokens=*" %%f in ('wmic cpu get NumberOfCores /value ^| find "="') do set %%f

And then execute like this:

GetNumberOfCores.cmd

echo %NumberOfCores%

The script will set a environment variable named %NumberOfCores% and it will contain the number of processors.

kiewic
  • 14,245
  • 11
  • 71
  • 90
  • 2
    When executing on the command line I had to replace the double `%%` with single `%`. Like: `for /f "tokens=*" %f in ('wmic cpu get NumberOfCores /value ^| find "="') do set %f` – BatteryBackupUnit Sep 06 '17 at 06:38
0

In order to check the absence of physical sockets run:

wmic cpu get SocketDesignation
Jonathan Argentiero
  • 5,437
  • 8
  • 28
  • 32
  • this command returns `CPU 1`. What do you mean by absence of physical sockets? A CPU can't be present on a motherboard without a socket isn't it? I believe this command simply tells you the number of CPU sockets on your machine. – RBT Mar 21 '17 at 12:53