Skip to main content

How to Get the Chassis Type (Laptop, Desktop, Server) in a Batch Script

When writing system inventory or configuration scripts, it's often useful to know the physical form factor of the machine you're running on. A script might need to apply different power settings for a laptop than for a desktop, or it might skip certain hardware checks if it detects it's running on a server.

This guide will teach you how to reliably determine the chassis type of a computer using the powerful, built-in WMIC (Windows Management Instrumentation) command. You will learn how to query the system's "enclosure" information and how to translate the numeric code it provides into a human-readable description like "Desktop" or "Laptop".

The Core Command: WMIC SYSTEMENCLOSURE

The WMIC (Windows Management Instrumentation Command-line) utility is the definitive tool for querying detailed hardware information. To find the chassis type, we query the SYSTEMENCLOSURE alias, which represents the physical container of the computer.

Command: WMIC SYSTEMENCLOSURE GET ChassisTypes

The Key Property: ChassisTypes

The ChassisTypes property is the specific piece of information we need. However, it does not return a simple string like "Laptop". Instead, it returns a numeric code that corresponds to a standard list of chassis types defined by the industry (in the SMBIOS specification). Our script will need to translate this code.

Output::

ChassisTypes
{9}

In this example, the system returned the code 9, which means "Laptop".

The Chassis Type Codes (Translation Table)

Here are the most common numeric codes and their meanings. Your script will use this "lookup table" to interpret the result from WMIC.

CodeChassis Type
1Other
2Unknown
3Desktop
4Low Profile Desktop
5Pizza Box
6Mini Tower
7Tower
8Portable
9Laptop
10Notebook
11Hand Held
12Docking Station
14Sub Notebook
17Main Server Chassis

Example Script: Getting and Interpreting the Chassis Type

This script executes the WMIC command, captures the numeric code, and then uses a series of IF statements to translate that code into a user-friendly description.

@ECHO OFF
SETLOCAL
SET "ChassisCode="
SET "ChassisType=Unknown"

ECHO --- Determining System Chassis Type ---
ECHO.

REM 'skip=1' ignores the header line.
REM 'delims={,' splits the output to handle the {9} format.
FOR /F "skip=1 tokens=1 delims={," %%C IN (
'WMIC SYSTEMENCLOSURE GET ChassisTypes'
) DO (
SET "ChassisCode=%%C"
GOTO :FoundCode
)

:FoundCode
REM Clean the variable of any invisible trailing characters.
FOR %%N IN ("%ChassisCode%") DO SET "ChassisCode=%%~N"

IF NOT DEFINED ChassisCode GOTO :DisplayResult

REM --- Translate the code to a friendly name ---
IF "%ChassisCode%"=="3" SET "ChassisType=Desktop"
IF "%ChassisCode%"=="4" SET "ChassisType=Low Profile Desktop"
IF "%ChassisCode%"=="6" SET "ChassisType=Mini Tower"
IF "%ChassisCode%"=="7" SET "ChassisType=Tower"
IF "%ChassisCode%"=="8" SET "ChassisType=Portable"
IF "%ChassisCode%"=="9" SET "ChassisType=Laptop"
IF "%ChassisCode%"=="10" SET "ChassisType=Notebook"
IF "%ChassisCode%"=="17" SET "ChassisType=Main Server"

:DisplayResult
ECHO The detected chassis type is: %ChassisType% (Code: %ChassisCode%)

ENDLOCAL

How the script works:

  1. WMIC ...: The command is executed, and its output (e.g., ChassisTypes {9}) is captured by the FOR /F loop.
  2. skip=1: This ignores the header line ("ChassisTypes").
  3. tokens=1 delims={,: This is a trick to parse the output. It tells the loop to use the { and , characters as delimiters and to only grab the first token. This effectively extracts the number 9 from a string like {9}.
  4. GOTO :FoundCode: We use GOTO to exit the loop after the first line of data is processed.
  5. IF "%ChassisCode%"=="3" ...: This block of IF statements acts as our lookup table, comparing the numeric code to known values and setting a friendly ChassisType string.

Common Pitfalls and How to Solve Them

  • Administrator Rights: While this query may work as a standard user, WMIC is always most reliable when run as an Administrator. This ensures it has full access to the hardware information layer.

  • Multiple Values: Some systems, especially servers with complex hardware, might report multiple chassis types (e.g., {17, 1}). The simple batch script above will only capture the first number in the list.

    • Solution: For these rare and complex cases, a PowerShell script would be more robust as it can natively handle arrays. For most standard PCs and laptops, however, the batch script is perfectly adequate.
  • OEM Accuracy: The value returned is dependent on the computer's manufacturer (OEM) correctly setting this information in the system's firmware (BIOS/UEFI). On some generic or custom-built machines, this value might be "Unknown" (2) or "Other" (1).

Practical Example: A Power Plan Configuration Script

This script intelligently applies an appropriate power plan based on the type of computer it's running on. It sets "High performance" for desktops and servers but "Balanced" for laptops.

@ECHO OFF
SETLOCAL

REM --- Standard GUIDs for default plans ---
SET "BalancedGUID=381b4222-f694-41f0-9685-ff5bb260df2e"
SET "HighPerfGUID=8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c"

ECHO --- Smart Power Plan Setter ---
ECHO Determining chassis type to apply the best power plan...

CALL :GetChassisType ChassisType
ECHO Detected type: %ChassisType%

IF /I "%ChassisType%"=="Laptop" GOTO :SetBalanced
IF /I "%ChassisType%"=="Notebook" GOTO :SetBalanced
IF /I "%ChassisType%"=="Portable" GOTO :SetBalanced

:SetHighPerf
ECHO Applying 'High performance' plan for a desktop/server...
powercfg /SETACTIVE %HighPerfGUID%
GOTO :End

:SetBalanced
ECHO Applying 'Balanced' plan for a portable device...
powercfg /SETACTIVE %BalancedGUID%
GOTO :End

:GetChassisType
SET "Code="
FOR /F "skip=1 tokens=1 delims={," %%C IN ('WMIC SYSTEMENCLOSURE GET ChassisTypes') DO (
SET "Code=%%C" & GOTO :GotCode
)
:GotCode
FOR %%N IN ("%Code%") DO SET "Code=%%~N"

SET "TypeName=Unknown"
IF "%Code%"=="3" SET "TypeName=Desktop"
IF "%Code%"=="9" SET "TypeName=Laptop"
IF "%Code%"=="10" SET "TypeName=Notebook"
IF "%Code%"=="17" SET "TypeName=Main Server"

SET "%1=%TypeName%"
GOTO :EOF

:End
ECHO --- Configuration complete ---
ENDLOCAL

Conclusion

The WMIC SYSTEMENCLOSURE GET ChassisTypes command is the standard and most reliable method for determining a computer's physical form factor from a batch script.

  • The command returns a numeric code, not a text string.
  • Your script must contain IF statements to translate this code into a meaningful name like "Desktop" or "Laptop".
  • Run your script as an Administrator for the most accurate results.

By using this WMIC query, you can create "hardware-aware" scripts that adapt their behavior to suit the type of machine they are running on.