How to

enumerate sound devices

Published: 7. February 2012 | Updated: 7. 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_SoundDevice");
ManagementObjectCollection collection = searcher.Get();

var items = new List<Win32_SoundDevice>();
foreach (ManagementObject obj in collection)
    var item = new Win32_SoundDevice();
    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.DMABufferSize = (ushort?)obj["DMABufferSize"];
    item.ErrorCleared = (bool?)obj["ErrorCleared"];
    item.ErrorDescription = (string)obj["ErrorDescription"];
    item.InstallDate = (DateTime?)obj["InstallDate"];
    item.LastErrorCode = (uint?)obj["LastErrorCode"];
    item.Manufacturer = (string)obj["Manufacturer"];
    item.MPU401Address = (uint?)obj["MPU401Address"];
    item.Name = (string)obj["Name"];
    item.PNPDeviceID = (string)obj["PNPDeviceID"];
    item.PowerManagementCapabilities = (ushort[])obj["PowerManagementCapabilities"];
    item.PowerManagementSupported = (bool?)obj["PowerManagementSupported"];
    item.ProductName = (string)obj["ProductName"];
    item.Status = (string)obj["Status"];
    item.StatusInfo = (ushort?)obj["StatusInfo"];
    item.SystemCreationClassName = (string)obj["SystemCreationClassName"];
    item.SystemName = (string)obj["SystemName"];



public class Win32_SoundDevice
    public ushort? Availability;
    public string Caption;
    public uint? ConfigManagerErrorCode;
    public bool? ConfigManagerUserConfig;
    public string CreationClassName;
    public string Description;
    public string DeviceID;
    public ushort? DMABufferSize;
    public bool? ErrorCleared;
    public string ErrorDescription;
    public DateTime? InstallDate;
    public uint? LastErrorCode;
    public string Manufacturer;
    public uint? MPU401Address;
    public string Name;
    public string PNPDeviceID;
    public ushort[] PowerManagementCapabilities;
    public bool? PowerManagementSupported;
    public string ProductName;
    public string Status;
    public ushort? StatusInfo;
    public string SystemCreationClassName;
    public string SystemName;
Send us feedback about this snippet »

Related Snippets: