using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Management;//這個別忘了加哦
//Colder By :linqifo074 Love Lyf secrectly!
//U should reserve this Message for
//commercial use!!!
namespace JudgeIslabtop
...{
public partial class Form1 : Form
...{
public Form1()
...{
InitializeComponent();
}
public enum ChassisTypes
...{// 其他的太多了,E文水平不高,沒法翻譯,baidu也沒有用,如果你會
//翻譯可以告訴我
Other = 1,//其他類型
Unknown,
Desktop台式機,
LowProfileDesktop,
PizzaBox,
MiniTower,
Tower,//貌似塔式服務器?
Portable,
Laptop膝上型電腦,
Notebook筆記本電腦,//10
Handheld,//手持型的
DockingStation,
AllInOne,
SubNotebook輕量級便攜式計算機,
SpaceSaving,
LunchBox,
MainSystemChassis,
ExpansionChassis,
SubChassis,
BusExpansionChassis,
PeripheralChassis,
StorageChassis,
RackMountChassis,
SealedCasePC
}
public static ChassisTypes GetCurrentChassisType()
...{//這個類的用法你可以查閱msdn,這裡只告訴你方法
//代碼也很簡單,復制粘貼一下就可以用了
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;//返回未知類型
}
private void button1_Click(object sender, EventArgs e)
...{
MessageBox.Show ( GetCurrentChassisType().ToString() );
}
}
}