MSDN Community - Windows API Reference

DeviceInformation Class

Represents information about a device. This class provides a way to discover devices connected to the system and retrieve their properties.

Namespace

Windows.Devices

Syntax

public sealed class DeviceInformation

Remarks

The DeviceInformation class is used to represent a device found by a DeviceWatcher or returned by other device enumeration APIs. Each instance of DeviceInformation contains a unique identifier (Id) and a collection of properties that describe the device.

You typically don't instantiate DeviceInformation directly. Instead, you obtain instances through methods like DeviceInformation.FindAllAsync or by processing events from a DeviceWatcher.

Methods

Method Description
static IAsyncOperation<DeviceInformationCollection> FindAllAsync() Retrieves a collection of all devices on the system.
static IAsyncOperation<DeviceInformationCollection> FindAllAsync(string aqsFilter) Retrieves a collection of devices that match the specified query string.
static IAsyncOperation<DeviceInformationCollection> FindAllAsync(string aqsFilter, IIterable<string> additionalProperties) Retrieves a collection of devices that match the specified query string and includes additional requested properties.
static IAsyncOperation<DeviceInformation> CreateFromIdAsync(string deviceId) Creates a DeviceInformation object from a device identifier.
static IAsyncOperation<DeviceInformation> CreateFromIdAsync(string deviceId, IIterable<string> additionalProperties) Creates a DeviceInformation object from a device identifier, including additional requested properties.
static string GetIdFromAqsFilter(string aqsFilter) Returns the device ID from an AQS filter string.

Properties

Property Description
string Id { get; } Gets the unique identifier for the device.
string Name { get; } Gets the user-friendly name of the device.
IReadOnlyDictionary<string, object> Properties { get; } Gets a read-only dictionary containing the properties of the device.
string Kind { get; } Gets the kind of device. This property is essential for filtering and identifying device types.

Known Property Keys

The Properties dictionary can contain various keys depending on the device kind. Some common keys are defined in other related classes and interfaces. Here are a few examples:

Refer to the documentation for specific device interface classes (e.g., Windows.Devices.Bluetooth.BluetoothDevice) for a comprehensive list of properties relevant to that device type.

Device Kinds

The Kind property specifies the type of device. Common values include:

Example Usage

The following example shows how to find all cameras connected to the system and display their names:

using System;
using System.Collections.Generic;
using Windows.Devices;
using Windows.Devices.Enumeration;
using Windows.Foundation;

public class DeviceDiscovery
{
    public async void FindCameras()
    {
        string aqsFilter = "System.Devices.DevInterface.Class == \"Image\""; // Filter for cameras

        try
        {
            DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(aqsFilter);

            if (devices.Count > 0)
            {
                Console.WriteLine("Found Cameras:");
                foreach (DeviceInformation device in devices)
                {
                    Console.WriteLine($"- {device.Name} (ID: {device.Id})");
                }
            }
            else
            {
                Console.WriteLine("No cameras found.");
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error finding devices: {ex.Message}");
        }
    }
}

Make sure to declare the appropriate capabilities in your application manifest (e.g., Device and Media for accessing devices).