How to Get the CPU Model Name in Batch Script
When creating diagnostic reports, performing system inventories, or checking if a computer meets the minimum requirements for a piece of software, you often need to identify the Central Processing Unit (CPU). The CPU's model name (e.g., "Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz") provides this crucial piece of information.
This guide will teach you how to use the built-in WMIC (Windows Management Instrumentation Command-line) utility to query the system for the exact model name of its processor. You will learn the simple command to display the name and the standard scripting pattern to capture this information into a variable.
The Core Command: WMIC CPU GET Name
Windows does not have a simple environment variable like %CPU_MODEL%. To get detailed hardware information, we must query the Windows Management Instrumentation (WMI) layer. The WMIC utility is the command-line tool for this.
The specific command to get the processor name is:
WMIC CPU GET Name
WMIC: The command-line utility.CPU: The WMI "alias" for theWin32_Processorclass, which contains detailed information about the system's processor(s).GET Name: The specific property we want to retrieve, which is the full model name string.
Basic Example: Displaying the CPU Name
You can run this command directly in a command prompt to see the CPU information for your current machine.
@ECHO OFF
ECHO --- Querying CPU Model Name ---
ECHO.
WMIC CPU GET Name
The output from WMIC is formatted with a header ("Name") and the value on the next line, often followed by extra blank lines.
--- Querying CPU Model Name ---
Name
Intel(R) Core(TM) i7-8700K CPU @ 3.70GHz
How to Capture the CPU Name in a Variable
To use the CPU name in a script (e.g., to write it to a log file), you need to capture it into a variable. The standard method for parsing WMIC output is to use a FOR /F loop.
@ECHO OFF
SET "CPU_NAME="
ECHO --- Capturing CPU Model Name ---
REM 'skip=1' ignores the "Name" header line.
FOR /F "skip=1 delims=" %%N IN ('WMIC CPU GET Name') DO (
SET "CPU_NAME=%%N"
GOTO :NameCaptured
)
:NameCaptured
IF NOT DEFINED CPU_NAME (
ECHO [FAILURE] Could not retrieve the CPU name.
GOTO :EOF
)
ECHO.
ECHO The captured CPU name is: %CPU_NAME%
skip=1 delims=: This tells theFORloop to ignore the first line of output (the header) and to treat the entire line as a single token.GOTO :NameCaptured: This is a crucial optimization. It makes the loop exit immediately after it has processed the first line of data, preventing theCPU_NAMEvariable from being overwritten by subsequent blank lines.
How the Method Works
The WMIC CPU GET Name command is a user-friendly alias for a more complex WMI query. Under the hood, it is querying the Win32_Processor WMI class and asking for the value of the Name property. This information is read directly from the hardware abstraction layer of the operating system, making it an authoritative source for the CPU's identity.
Common Pitfalls and How to Solve Them
Problem: Parsing the WMIC Output is Tricky
The output from WMIC is designed to be somewhat human-readable, but its extra header, trailing spaces, and blank lines can make it difficult to parse in a script if you're not careful.
Solution: The FOR /F "skip=1 delims=" loop combined with an immediate GOTO is the most robust and recommended pattern for capturing WMIC data. It reliably isolates the single line of data you need and ignores the rest of the noisy output.
Problem: Systems with Multiple Physical CPUs
On high-end workstations or servers with more than one physical CPU socket, the WMIC command will list the name for each processor.
Example Output on a Dual-CPU Server:
Name
Intel(R) Xeon(R) Gold 6248R CPU @ 3.00GHz
Intel(R) Xeon(R) Gold 6248R CPU @ 3.00GHz
Solution: The simple script provided will only capture the last CPU in the list. For most inventory purposes, where the CPUs are identical, this is acceptable. If you need to capture all of them, you would need to use a more complex script with pseudo-arrays to store each line of the output.
Practical Example: A Simple System Profiler Script
This script gathers several key pieces of system information (the OS, the CPU, and the amount of RAM) and saves them to a simple report file.
@ECHO OFF
SETLOCAL
SET "REPORT_FILE=%USERPROFILE%\Desktop\System_Profile.txt"
ECHO --- System Profile Generator ---
ECHO Creating report at: "%REPORT_FILE%"
(
ECHO System Profile for: %COMPUTERNAME%
ECHO Report generated on: %DATE% @ %TIME%
ECHO ------------------------------------
ECHO.
REM Get OS Caption
FOR /F "tokens=*" %%O IN ('WMIC OS GET Caption') DO SET "OS_CAPTION=%%O"
ECHO Operating System: %OS_CAPTION%
REM Get CPU Name
FOR /F "skip=1 delims=" %%C IN ('WMIC CPU GET Name') DO SET "CPU_NAME=%%C"
ECHO Processor: %CPU_NAME%
REM Get Total Physical Memory
FOR /F "skip=1" %%R IN ('WMIC COMPUTERSYSTEM GET TotalPhysicalMemory') DO SET "RAM_BYTES=%%R"
SET /A "RAM_GB = %RAM_BYTES% / 1024 / 1024 / 1024"
ECHO Installed RAM: %RAM_GB% GB (%RAM_BYTES% bytes)
) > "%REPORT_FILE%"
ECHO.
ECHO --- Report Complete ---
START "" "%REPORT_FILE%"
ENDLOCAL
Conclusion
The WMIC CPU GET Name command is the standard, built-in, and most reliable method for retrieving a computer's processor model from a batch script.
Key takeaways:
- Use
WMIC CPU GET Nameto query the local machine. - Use a
FOR /F "skip=1 delims="loop with aGOTOto capture the clean CPU name into a variable. - This method is authoritative and works on all modern Windows systems without any external tools.
- You can combine this with other
WMICqueries to build powerful system inventory and reporting scripts.