How to

enumerate keyboards

Published: 12. February 2012 | Updated: 12. February 2012
License: Microsoft Public License (MS-PL)
Categories: Windows » Hardware
Tags: C# Hardware Windows WMI
Was this snippet helpful for you? YESYES / NONO
Get Analyzant!

Check your entire website from code to content in minutes with Analyzant, the free analysis suite.

Free download at

Import namespaces

using System;
using System.Collections.Generic;
using System.Management; // requires adding System.Management reference to project


ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Keyboard");
ManagementObjectCollection collection = searcher.Get();

var items = new List<Win32_Keyboard>();
foreach (ManagementObject obj in collection)
    var item = new Win32_Keyboard();
    item.Availability = (ushort?)obj["Availability"];
    item.Caption = (string)obj["Caption"];
    item.ConfigManagerErrorCode = (uint?)obj["ConfigManagerErrorCode"];
    item.ConfigManagerUserConfig = (bool?)obj["ConfigManagerUserConfig"];
    item.CreationClassName = (string)obj["CreationClassName"];
    item.Description = (string)obj["Description"];
    item.DeviceID = (string)obj["DeviceID"];
    item.ErrorCleared = (bool?)obj["ErrorCleared"];
    item.ErrorDescription = (string)obj["ErrorDescription"];
    item.InstallDate = (DateTime?)obj["InstallDate"];
    item.IsLocked = (bool?)obj["IsLocked"];
    item.LastErrorCode = (uint?)obj["LastErrorCode"];
    item.Layout = (string)obj["Layout"];
    item.Name = (string)obj["Name"];
    item.NumberOfFunctionKeys = (ushort?)obj["NumberOfFunctionKeys"];
    item.Password = (ushort?)obj["Password"];
    item.PNPDeviceID = (string)obj["PNPDeviceID"];
    item.PowerManagementCapabilities = (ushort[])obj["PowerManagementCapabilities"];
    item.PowerManagementSupported = (bool?)obj["PowerManagementSupported"];
    item.Status = (string)obj["Status"];
    item.StatusInfo = (ushort?)obj["StatusInfo"];
    item.SystemCreationClassName = (string)obj["SystemCreationClassName"];
    item.SystemName = (string)obj["SystemName"];



public class Win32_Keyboard
    public ushort? Availability;
    public string Caption;
    public uint? ConfigManagerErrorCode;
    public bool? ConfigManagerUserConfig;
    public string CreationClassName;
    public string Description;
    public string DeviceID;
    public bool? ErrorCleared;
    public string ErrorDescription;
    public DateTime? InstallDate;
    public bool? IsLocked;
    public uint? LastErrorCode;
    public string Layout;
    public string Name;
    public ushort? NumberOfFunctionKeys;
    public ushort? Password;
    public string PNPDeviceID;
    public ushort[] PowerManagementCapabilities;
    public bool? PowerManagementSupported;
    public string Status;
    public ushort? StatusInfo;
    public string SystemCreationClassName;
    public string SystemName;
Send us feedback about this snippet »

Related Snippets: