Home
Blog
Contact
Mailing List
Software
Blog
Twitter
|
<< Back To All Blogs
Determining if a computer is a laptop or desktop in C#
Monday, August 24th, 2009
There are often situations in which it is helpful to know if a user is running a laptop or desktop in C#, and I figured I would share one of the many ways to do so. The WMI class Win32_SystemEnclosure includes the hardware type for the physical case of the computer. So, running a simple WMI query will present you with some information. This base query is:
SELECT * FROM Win32_SystemEnclosure
There are a number of objects returned from this query, but for our example, we are interested in the UInt16 array returned ChassisTypes. You can cast this to an array as follows:
ushort[] chassisTypes = (ushort[])result["ChassisTypes"];
As you can clearly see, this is an array of ushort values for the chassis type. The values of these chassis types are available on MSDN, but for ease of use, I wrote a quick switch statement to convert the types to a string value:
public static string ConvertChassisType(ushort Input)
{
switch (Input)
{
case 1:
return "Other";
case 2:
return "Unknown";
case 3:
return "Desktop";
case 4:
return "Low Profile Desktop";
case 5:
return "Pizza Box";
case 6:
return "Mini Tower";
case 7:
return "Tower";
case 8:
return "Portable";
case 9:
return "Laptop";
case 10:
return "Notebook";
case 11:
return "Hand Held";
case 12:
return "Docking Station";
case 13:
return "All in One";
case 14:
return "Sub Notebook";
case 15:
return "Space-Saving";
case 16:
return "Lunch Box";
case 17:
return "Main System Chassis";
case 18:
return "Expansion Chassis";
case 19:
return "SubChassis";
case 20:
return "Bus Expansion Chassis";
case 21:
return "Peripheral Chassis";
case 22:
return "Storage Chassis";
case 23:
return "Rack Mount Chassis";
case 24:
return "Sealed-Case PC";
default:
return "";
}
}
You can then use these values to determine (either with the ushort value or the string value) if the computer in question is a laptop or desktop (or a number of different options).
WMIin' Tom Out.
Tags
CSharp
Howto
Related Blogs
Reading an XML file using LINQ
Reading Digital Signatures from InfoPath Forms in MOSS 2007 and WSS 3.0 Workflow
SharePoint Web Services, .NET 3.5, and Authentication Issues
Validate a Windows Username and Password against Active Directory
Autostarting a Windows Service directly after install in C#
Comments
Katrina said on Monday, August 24th, 2009 @ 10:26 AM
I can't say that this article was interesting to me, because I didn't understand it. It did, however, instill in me the deep sense of calm that springs from being reminded that you really know what you're doing.
Add A Comment
Name:
URL:
Email Address: (not public, used to send notifications on further comments)
Comments:

Enter the text above, except for the 1st and last character:
|