Mailing List


Active Directory Products
Object Compare
Permission Compare

IPhone Products
Calls To Calendar
SMS To Gmail
Voicemail To Gmail

How Long For Me


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

Updating an LDAP Property in C#
Enumerating a user secure certificate store in C#
Fixing "Error in loading DLL" in SharePoint
Using MOSS and WSS SharePoint Workflow to Resize Images in an Image Library
Calling .NET WebService From PHP


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