Skip to content

Instantly share code, notes, and snippets.

@marianz-bonfire
Created September 14, 2024 02:46
Show Gist options
  • Save marianz-bonfire/7feedcd0d302e613f2d4bf0b9b29661d to your computer and use it in GitHub Desktop.
Save marianz-bonfire/7feedcd0d302e613f2d4bf0b9b29661d to your computer and use it in GitHub Desktop.
C# Check if the machine is Laptop
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;
}
@marianz-bonfire
Copy link
Author

Make sure usings are included

using System.Diagnostics;
using System.Management; 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment