如何判断计算机的类型?一个简单的方法是通过 WMI 查询系统信息 Win32_SystemEnclosure 类,ChassisTypes指示计算机类型。有 22 种已知类型,多数我们平时见不到,最常见的当然是Desptop(3)和Laptop(9)(较老型号),Notebook(10)。
需要引用 System.Management 命名空间。
以下是示例代码:
using System.Management;
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;
}
本文来自CSDN博客,转载请标明出处:
http://blog.csdn.net/vrhero/archive/2007/11/08/1874042.aspx