How to Get the System Manufacturer and Model in Batch Script
Identifying the hardware manufacturer and model of a Windows machine is a common requirement for inventory management, automated driver installation, warranty lookups, and conditional logic in deployment scripts. Rather than physically inspecting the label on a laptop or desktop chassis, Batch Script can query this information programmatically through WMI (Windows Management Instrumentation) or the systeminfo command.
In this guide, we will explore multiple methods to retrieve the system manufacturer, model name, and serial number using Batch Script.
Method 1: Using WMIC (The Standard Approach)
The wmic command provides direct access to the Win32_ComputerSystem class, which contains the manufacturer and model properties.
@echo off
setlocal
echo Retrieving System Manufacturer and Model...
echo =============================================
:: Get Manufacturer
set "manufacturer="
for /f "tokens=2 delims==" %%A in ('wmic computersystem get Manufacturer /value 2^>nul ^| find "="') do (
set "manufacturer=%%A"
)
:: Get Model
set "model="
for /f "tokens=2 delims==" %%A in ('wmic computersystem get Model /value 2^>nul ^| find "="') do (
set "model=%%A"
)
if not defined manufacturer (
echo [ERROR] Could not retrieve system information via WMI.
pause
exit /b 1
)
echo Manufacturer: %manufacturer%
echo Model: %model%
pause
The wmic command-line utility is deprecated as of Windows 10 version 21H1 and may be removed in future Windows releases. While it remains functional on current systems, consider using the PowerShell alternative in Method 4 for forward compatibility. See the deprecation note in Method 4 for the recommended replacement.
Adding the Serial Number (Service Tag)
The serial number (or Service Tag on Dell machines) is stored in a different WMI class: Win32_BIOS.
@echo off
setlocal
echo =============================================
echo SYSTEM HARDWARE INFORMATION
echo =============================================
echo.
:: Manufacturer
set "mfr="
for /f "tokens=2 delims==" %%A in ('wmic computersystem get Manufacturer /value 2^>nul ^| find "="') do set "mfr=%%A"
:: Model
set "mdl="
for /f "tokens=2 delims==" %%A in ('wmic computersystem get Model /value 2^>nul ^| find "="') do set "mdl=%%A"
:: Serial Number / Service Tag
set "serial="
for /f "tokens=2 delims==" %%A in ('wmic bios get SerialNumber /value 2^>nul ^| find "="') do set "serial=%%A"
:: System SKU (product number on HP machines)
set "sku="
for /f "tokens=2 delims==" %%A in ('wmic computersystem get SystemSKUNumber /value 2^>nul ^| find "="') do set "sku=%%A"
echo Manufacturer: %mfr%
echo Model: %mdl%
echo Serial Number: %serial%
echo System SKU: %sku%
pause
Common Outputs by Manufacturer
| Manufacturer | Typical Model Output | Serial Number Label |
|---|---|---|
| Dell Inc. | Latitude 5520, OptiPlex 7090 | Service Tag |
| HP | HP EliteBook 840 G8 | Product ID |
| Lenovo | 20U9CTO1WW (cryptic) | Machine Type |
| Microsoft Corporation | Surface Pro 7 | Device Serial |
| VMware, Inc. | VMware Virtual Platform | VMware-xx-xx |
Lenovo machines often report cryptic internal model codes instead of marketing names. The human-readable name (like "ThinkPad T14") is typically stored in the Win32_ComputerSystemProduct class under the Version property. See Method 3.
Method 2: Using SYSTEMINFO
The systeminfo command provides manufacturer and model information as part of its comprehensive output. While slower than wmic, it is universally available.
@echo off
setlocal enabledelayedexpansion
echo Parsing systeminfo for hardware details...
:: Run systeminfo once and cache the output to avoid calling it twice
set "tmpfile=%temp%\sysinfo_%RANDOM%.txt"
systeminfo > "%tmpfile%" 2>nul
set "mfr="
set "mdl="
for /f "tokens=1* delims=:" %%A in ('findstr /c:"System Manufacturer" /c:"System Model" "%tmpfile%"') do (
set "label=%%A"
set "value=%%B"
:: Trim leading spaces from the value
if defined value (
for /f "tokens=*" %%V in ("!value!") do set "value=%%V"
)
echo !label:~0,20!: !value!
)
del "%tmpfile%" 2>nul
pause
The labels "System Manufacturer" and "System Model" are translated on non-English versions of Windows. On a German system, they become "Systemhersteller" and "Systemmodell." On a French system, they become "Fabricant du système" and "Modèle du système." This makes systeminfo parsing unreliable for international deployments. Always prefer wmic or PowerShell for non-English environments.
Method 3: Getting the Lenovo Friendly Name
As noted above, Lenovo machines report internal part numbers instead of marketing names in the Model field. To get the recognizable name (e.g., "ThinkPad X1 Carbon Gen 9"), query the Win32_ComputerSystemProduct class.
@echo off
setlocal
echo Retrieving Lenovo-friendly model name...
:: The Version field in ComputerSystemProduct contains the marketing name
set "friendly_name="
for /f "tokens=2 delims==" %%A in ('wmic csproduct get Version /value 2^>nul ^| find "="') do set "friendly_name=%%A"
:: Also get the standard model for reference
set "internal_model="
for /f "tokens=2 delims==" %%A in ('wmic computersystem get Model /value 2^>nul ^| find "="') do set "internal_model=%%A"
echo Internal Model: %internal_model%
echo Friendly Name: %friendly_name%
:: The friendly name may be empty on non-Lenovo hardware
if not defined friendly_name (
echo.
echo [INFO] The Version field is empty. This is normal on non-Lenovo hardware.
echo Use the Model field instead.
)
pause
On a Lenovo ThinkPad T14 Gen 2, this would output:
Internal Model: 20W0CTO1WW
Friendly Name: ThinkPad T14 Gen 2
On non-Lenovo hardware, the Version field in Win32_ComputerSystemProduct may be empty, contain a generic string, or duplicate the model number. Always check whether the value is defined before using it, and fall back to the standard Win32_ComputerSystem.Model field when it is empty.
Method 4: PowerShell Alternative (Recommended for New Scripts)
Since Microsoft is gradually deprecating wmic, the modern approach uses PowerShell's Get-CimInstance cmdlet.
@echo off
setlocal enabledelayedexpansion
echo Retrieving hardware info via PowerShell...
echo.
set "mfr="
set "mdl="
set "serial="
for /f "usebackq tokens=1* delims==" %%A in (`powershell -NoProfile -Command ^
"$cs = Get-CimInstance Win32_ComputerSystem; ^
$bios = Get-CimInstance Win32_BIOS; ^
Write-Output ('Manufacturer=' + $cs.Manufacturer); ^
Write-Output ('Model=' + $cs.Model); ^
Write-Output ('Serial=' + $bios.SerialNumber)" 2^>nul`) do (
if "%%A"=="Manufacturer" set "mfr=%%B"
if "%%A"=="Model" set "mdl=%%B"
if "%%A"=="Serial" set "serial=%%B"
)
if not defined mfr (
echo [ERROR] Could not retrieve hardware information via PowerShell.
pause
exit /b 1
)
echo Manufacturer: !mfr!
echo Model: !mdl!
echo Serial: !serial!
pause
Get-CimInstance is the recommended replacement for both wmic.exe and the older Get-WmiObject cmdlet (which was removed in PowerShell 7+). The key/value output format used here (Write-Output ('Property=' + $value)) mirrors the wmic /value pattern, making it easy to parse from Batch with the same tokens and delims approach.
Practical Use Case: Conditional Driver Installation
A common real-world scenario is a deployment script that installs different drivers based on the detected hardware model.
@echo off
setlocal enabledelayedexpansion
:: Get the model
set "model="
for /f "tokens=2 delims==" %%A in ('wmic computersystem get Model /value 2^>nul ^| find "="') do set "model=%%A"
if not defined model (
echo [ERROR] Could not detect hardware model.
pause
exit /b 1
)
echo Detected Model: !model!
set "driver_found=0"
:: Install the correct display driver based on model
echo !model! | findstr /i "Latitude 5520" >nul
if !errorlevel! equ 0 (
echo Installing Dell Latitude 5520 display driver...
start /wait "" "drivers\dell5520_display.exe" /s
set "driver_found=1"
goto :done
)
echo !model! | findstr /i "EliteBook 840" >nul
if !errorlevel! equ 0 (
echo Installing HP EliteBook 840 display driver...
start /wait "" "drivers\hp840_display.exe" /s
set "driver_found=1"
goto :done
)
echo !model! | findstr /i "Surface Pro" >nul
if !errorlevel! equ 0 (
echo Installing Surface Pro display driver...
start /wait "" "drivers\surface_display.msi" /quiet
set "driver_found=1"
goto :done
)
:done
if "!driver_found!"=="0" (
echo [WARNING] Model "!model!" is not in the driver mapping.
echo Skipping driver installation.
)
pause
Common Mistakes
The Wrong Way: Parsing WMIC Output Without /value Format
:: WRONG - Captures the header row and blank lines
for /f %%A in ('wmic computersystem get Manufacturer') do set "mfr=%%A"
echo %mfr%
Without using the /value format and find "=", the for /f loop captures the column header ("Manufacturer") as the first result, blank lines with trailing carriage returns, and the actual value in an unpredictable iteration order. The final value stored in %mfr% is often a blank line or the header text itself. Always use the /value format with find "=" to get clean, headerless key=value output.
The Wrong Way: Using SYSTEMINFO Internationally
:: WRONG - Fails on non-English OS
systeminfo | findstr "System Manufacturer"
The string "System Manufacturer" is localized. On a French system, you would need "Fabricant du système." Always use wmic or PowerShell for international deployments.
The Wrong Way: Assuming WMIC Output Has No Trailing Characters
:: WRONG - Stored value contains invisible trailing carriage return
for /f "tokens=2 delims==" %%A in ('wmic computersystem get Manufacturer /value ^| find "="') do set "mfr=%%A"
if "%mfr%"=="Dell Inc." echo Dell detected
WMIC outputs text in UTF-16 encoding with Windows-style line endings. When piped through find, trailing carriage return (\r) characters are preserved in the captured value. The variable %mfr% actually contains Dell Inc.\r, so the string comparison "%mfr%"=="Dell Inc." silently fails. Use findstr /i with a partial match instead of exact equality, or pipe the value through a trimming step. The practical example above demonstrates the findstr /i approach.
Best Practices
- Use
wmicwith/valueformat: The/valueoutput format (Property=Value) is the easiest to parse reliably in Batch, and piping throughfind "="strips header rows and blank lines. - Query
csproductfor Lenovo: Always checkWin32_ComputerSystemProduct.Versionfor human-readable Lenovo model names, and fall back toWin32_ComputerSystem.Modelon other hardware. - Include the Serial Number: For inventory and warranty scripts, always capture
Win32_BIOS.SerialNumberalongside the manufacturer and model. - Transition to PowerShell: As
wmicenters deprecation, begin transitioning inventory scripts to use embeddedGet-CimInstancecalls for forward compatibility. - Initialize variables before WMIC parsing: Always
set "var="before afor /floop that parses WMIC output. WMIC's trailing carriage returns can cause stale values to persist if the command produces no output. - Use partial matching for model comparisons: Due to WMIC's trailing
\rcharacters, useecho !model! | findstr /i "search string"rather than exact==string comparison. This also handles minor model name variations across BIOS revisions. - Add
2>nulto WMIC commands: Redirect stderr on allwmiccalls to prevent error messages (e.g., on systems where WMIC has been removed) from corrupting thefor /fparsing output.
Conclusion
Retrieving the system manufacturer and model in Batch Script is a foundational capability for IT automation. By querying the Win32_ComputerSystem and Win32_BIOS WMI classes through the wmic command, administrators can programmatically identify hardware, route conditional driver installations, and populate inventory databases. Understanding the quirks of different OEM naming conventions, particularly Lenovo's cryptic internal model codes, ensures that scripts produce accurate, meaningful output across diverse hardware fleets.