DeviceInformation class

2 out of 7 rated this helpful - Rate this topic

Represents a device. This class allows access to well-known device properties as well as additional properties specified during device enumeration.

Syntax


var deviceInformation = Windows.Devices.Enumeration.DeviceInformation;

Attributes

DualApiPartitionAttribute()
MarshalingBehaviorAttribute(Agile)
StaticAttribute(Windows.Devices.Enumeration.IDeviceInformationStatics, NTDDI_WIN8)
ThreadingAttribute(Both)
VersionAttribute(NTDDI_WIN8)

Members

The DeviceInformation class has these types of members:

Methods

The DeviceInformation class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
CreateFromIdAsync(String) Creates a DeviceInformation object from a DeviceInformation ID.
CreateFromIdAsync(String, IIterable(String)) Creates a DeviceInformation object from a DeviceInformation ID and a list of additional properties.
CreateWatcher() Creates a DeviceWatcher for all devices.
CreateWatcher(DeviceClass) Creates a DeviceWatcher for devices matching the specified DeviceClass.
CreateWatcher(String) Creates a DeviceWatcher for devices matching the specified Advanced Query Syntax (AQS) string.
CreateWatcher(String, IIterable(String)) Creates a DeviceWatcher for devices matching the specified Advanced Query Syntax (AQS) string and the specified collection of properties.
FindAllAsync() Enumerates all DeviceInformation objects.
FindAllAsync(DeviceClass) Enumerates DeviceInformation objects of the specified class.
FindAllAsync(String) Enumerates DeviceInformation objects matching the specified Advanced Query Syntax (AQS) string.
FindAllAsync(String, IIterable(String)) Enumerates DeviceInformation objects matching the specified Advanced Query Syntax (AQS) string and including the specified collection of properties.
GetGlyphThumbnailAsync Gets a glyph for the device.
GetThumbnailAsync Returns a thumbnail image for the device.
Update Updates the properties of an existing DeviceInformation object.

 

Properties

The DeviceInformation class has these properties.

PropertyAccess typeDescription

EnclosureLocation

Read-onlyThe physical location of the device in its enclosure.

Id

Read-onlyA string representing the identity of the device.

IsDefault

Read-onlyIndicates whether this device is the default device for the class.

IsEnabled

Read-onlyIndicates whether this device is enabled.

Name

Read-onlyThe name of the device.

Properties

Read-onlyProperty store containing well-known values as well as additional properties that can be specified during device enumeration.

 

Remarks

Successful completion of FindAllAsync results in a DeviceInformationCollection containing DeviceInformation objects.

If a call to CreateWatcher succeeds, a DeviceInformation object is passed to the added event for each device that is found.

CreateFromIdAsync creates a DeviceInformation object if successful.

The DeviceInformation class provides device information, but more specifically, it provides properties of the device interface, the interface that represents functionality that the device exposes. Multi-function devices may have more than one device interface. The physical object that a user sees as a device, is known as the device container, and has properties such as Manufacturer and ModelID. For a list of properties associated with device interfaces, device containers, and other PnP objects, see the list of canonical properties in How to retrieve additional properties for a device or PnP object. For tutorials on how to use the DeviceInformation class to get device information, see How to retrieve additional properties for a device or PnP object, How to retrieve related PnP objects, and Quickstart: Enumerating device containers.

Examples

This example incrementally enumerates devices, adding them to a list each time a device is found, and also handling removals and updates. The onAdded function that handles the added event takes a DeviceInformation object. After enumeration is complete, this example prints a list of devices. The example also prints a message if devices are added, updated, or removed after the initial enumeration completes.



<!DOCTYPE html>
<html>
<head>
    <title>Device Enumeration Sample</title>
    <script>
    var watcher;
    var deviceArray = new Array(); // Saves the enumeration results.

    function WatchDevices() {
        try {
            output.innerHTML = ""; // Clears output field.

            watcher = 
                Windows.Devices.Enumeration.DeviceInformation.createWatcher();
            // Add event handlers
            watcher.addEventListener("added", onAdded);
            watcher.addEventListener("removed", onRemoved);
            watcher.addEventListener("updated", onUpdated);
            watcher.addEventListener("enumerationcompleted", 
                onEnumerationCompleted);
            watcher.addEventListener("stopped", onStopped);
            // Start enumerating and listening for events
            watcher.start();
        } catch (e) {
            document.getElementById("statusMessage").innerHTML = 
                "Failed to create watcher, error: " + e.message;
        }
    }

    function stopWatcher() {
        try {
            watcher.stop();
        }
        catch (e) {
            document.getElementById("statusMessage").innerHTML = 
                "Failed to stop watcher: " + e.message;
        }
    }

    function onAdded(devinfo) {
        document.getElementById("output").innerHTML += "<p>Device added: " + 
            devinfo.name + "</p>";
        deviceArray.push(devinfo);
    }

    function onUpdated(devUpdate) {
        document.getElementById("output").innerHTML += "<p>Device updated.</p>";
        for (var i = 0; i < deviceArray.length; i++) {
            if (deviceArray[i].id == devUpdate.id) {
                deviceArray[i].update(devUpdate);
            }
        }
    }

    function onRemoved(devupdate) {
        document.getElementById("output").innerHTML += "<p>Device removed.</p>";
        for (var i = 0; i < deviceArray.length; i++) {
            if (deviceArray[i].id == devupdate.id) {
                deviceArray[i].slice(devupdate);
            }
        }
    }

    function onEnumerationCompleted(obj) {
        document.getElementById("output").innerHTML += 
            "<p>Enumeration Completed.</p>";
        printDeviceArray(document.getElementById("output"));
    }

    function onStopped(obj) {
        document.getElementById("output").innerHTML += "<p>Stopped.</p>";
    }


    // Prints the friendly name of the device interface, 
    // its ID (device interface path), and whether it is enabled.
    function printDevice(deviceInterface, outputDestination) {
        outputDestination.innerHTML += "<p>Name: " + 
            deviceInterface.name + "</p>"; 
        outputDestination.innerHTML += "<p>Interface ID: " + 
            deviceInterface.id + "</p>";    
        outputDestination.innerHTML += "<p>Enabled: " + 
            deviceInterface.isEnabled + "</p>";
        outputDestination.innerHTML += "<br />";
    }

    function printDeviceArray(outputDestination) {
        for (var i = 0; i < deviceArray.length; i++) {
            printDevice(deviceArray[i], outputDestination);
        }
    }

    </script>
</head>
<body role="application">
    <h1>Device Enumeration Sample</h1>
    <h2 >Input</h2>
    <div >            
            <div >
            <p>This example incrementally enumerates devices, adding them to a list each time a device is found, and also watching for updates.
               Once enumeration is complete, the list of devices is printed.</p> 
                <input type="button" value="Watch(All Devices)" onclick="WatchDevices()"/>
                <br /><br />

                <input type="button" value="Stop" onclick="stopWatcher()"/>
                <br /><br />
            </div>
    </div>

    <h2 > Output</h2>
            <div id="statusMessage"></div>
            <!--  Output -->
            <div  id="output"></div>
</body>
</html>
 


Requirements

Minimum supported client

Windows 8 [Windows Store apps, desktop apps]

Minimum supported server

Windows Server 2012 [Windows Store apps, desktop apps]

Namespace

Windows.Devices.Enumeration
Windows::Devices::Enumeration [C++]

Metadata

Windows.winmd

 

 

Build date: 12/4/2012

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.