Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check the machine type? laptop or desktop?

Tags:

c#

wmi

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;
}

like image 432
Cooper.Wu Avatar asked Jun 18 '09 15:06

Cooper.Wu


People also ask

How do I know if laptop or desktop?

Go to the search bar and type msinfo32. From the results, open the System Information application. Now click on the System Summary to get the full specifications of your laptop or PC.

How do I find the model of my laptop Windows 10?

Windows 11 or Windows 10In the Search Box, type System. In the list of search results, under settings, select System. Look for Model: in the System section.


1 Answers

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.

like image 110
Kevin Newman Avatar answered Oct 19 '22 03:10

Kevin Newman