How to check the machine type? laptop or desktop?

Cooper.Wu picture Cooper.Wu · Jun 18, 2009 · Viewed 23.4k times · Source

How to check current machine type? laptop or desktop ?

I got this from http://blog.csdn.net/antimatterworld/archive/2007/11/11/1878710.aspx ,it works well on my home machine(Win2003 on laptop), it returns "Portable", but failed on my work machine(Vista on laptop), it returns "Other".

here is the code:


public enum ChassisTypes
{
    Other = 1,
    Unknown,
    Desktop,
    LowProfileDesktop,
    PizzaBox,
    MiniTower,
    Tower,
    Portable,
    Laptop,
    Notebook,
    Handheld,
    DockingStation,
    AllInOne,
    SubNotebook,
    SpaceSaving,
    LunchBox,
    MainSystemChassis,
    ExpansionChassis,
    SubChassis,
    BusExpansionChassis,
    PeripheralChassis,
    StorageChassis,
    RackMountChassis,
    SealedCasePC
}

public static ChassisTypes GetCurrentChassisType()
{
    ManagementClass systemEnclosures = new ManagementClass("Win32_SystemEnclosure");
    foreach (ManagementObject obj in systemEnclosures.GetInstances())
    {
        foreach (int i in (UInt16[  ])(obj["ChassisTypes"]))
        {
             if (i > 0 && i < 25)
            {
                return (ChassisTypes)i;
            }
        }
    }
    return ChassisTypes.Unknown;
}

Answer

Kevin Newman picture Kevin Newman · Jun 18, 2009

Here's a good Microsoft article that suggests looking at a few other WMI classes to get a better idea of whether the computer is a laptop or desktop:
http://technet.microsoft.com/en-us/library/cc180825.aspx

Win32_SystemEnclosure, ChassisTypes(1)=10
Win32_Battery or Win32_PortableBattery
Win32_PCMCIAController
Win32_DriverVXD.Name = "pccard"
Win32_ComputerSystem.Manufacturer
Win32_ComputerSystem.Model

And it also suggests to look in the registry for the Power scheme.