Mailing List



NerdyHearn - Blog

<< 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";
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.


CSharp Howto

Related Blogs

SharePoint Web Services, .NET 3.5, and Authentication Issues
Creating a reusable web client for PUT, POST, and DELETE in C#
Retrieving data from SharePoint SOAP Requests using LINQ
Autostarting a Windows Service directly after install in C#
A quick way to find C++ method signatures for C# Interop


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



Email Address: (not public, used to send notifications on further comments)


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

NerdyHearn - Latest tech news relating to C#, ASP.NET, SharePoint, PHP, general development, and more. SaveMySerials - Protect yourself from theft, fire, natural disasters and more by recording your serial numbers