如何查看当前机器类型?笔记本电脑还是台式机?

我是从http://blog.csdn.net/antimatterworld/archive/2007/11/11/1878710.aspx获得的,它在我的家用计算机(笔记本电脑上为Win2003)上运行良好,返回“可移植”,但在我的工作计算机(笔记本电脑上为Vista)上失败,返回“其他”。

这是代码:
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;}

最佳答案

这是一篇很好的Microsoft文章,建议您查看其他一些WMI类,以更好地了解计算机是笔记本电脑还是台式机:
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

它还建议在注册表中查找电源方案。

09-25 21:37