Share via


Device.Services property

The Services property provides read-only access to a collection of all the services on the device.

This property is read-only.

Syntax

Services = Device.Services

Property value

Read-only servicesCollection object.

Remarks

The servicesCollection returned by the Services property can be accessed in three ways: by using a zero-based index, by using a Service Persistent Unique ID (PUID), and by using an Object Identifier (ObjectId).

The following code shows a servicesCollection accessed by using a zero-based numeric index.

var service = deviceObject.Services[0];

If the numeric index value is greater than or equal to the value returned by servicesCollection.Count, a JScript exception will be thrown.

In the following code, a Service PUID is used to access the servicesCollection.

var service = deviceObject.Services[servicePUID];

The Service PUID for a specific service can be obtained by using the WPD Automation name ObjectPersistentUniqueID that corresponds to the WPD PROPERTYKEY WPD_OBJECT_PERSISTENT_UNIQUE_ID; as in the following example:

var servicePUID = service.ObjectPersistentUniqueID;

For a complete list of WPD PROPERTYKEYs and their corresponding WPD Automation names, see Names for WPD PROPERTYKEYs.

Using a Service PUID to access a service collection is valid only for a collection obtained from the Services property. This is because a collection obtained from the Device.GetServicesByType method is already filtered by service type.

The ObjectId of a specific service can be obtained by using the WPD Automation name ObjectId that corresponds to the WPD PROPERTYKEY WPD_OBJECT_ID as in the following example:

var serviceObjectId = service.ObjectId;

For a complete list of WPD PROPERTYKEYs and their corresponding WPD Automation names, see Names for WPD PROPERTYKEYs.

Examples

The following JScript example uses the Services property to access the collection of all services on a Device object and then shows retrieving a service from the collection by using a numeric index, a Service PUID, and by using an ObjectId.

// The service object serviceByIndex is obtained using
// the index value 0.
var serviceByIndex = deviceObject.Services[0];

// The Service PUID of serviceByIndex is read using the
// ObjectPersistentUniqueID property.  
var servicePUID = serviceByIndex.ObjectPersistentUniqueID;

// The service object serviceByPUID, which is identical to
// the serviceByIndex object, is obtained by using the
// Service PUID of serviceByIndex. 
var serviceByPUID = deviceObject.Services[servicePUID];

// The ObjectId of serviceByIndex is read using the ObjectID
// property.
var serviceObjectId = serviceByIndex.ObjectId;

// The service object serviceByObjectId, which is identical to
// the serviceByIndex object, is obtained by using the ObjectId
// of serviceByIndex.
var serviceByObjectId = deviceObject.Services[serviceObjectId];

Requirements

Minimum supported client
Windows 7 [desktop apps only]
Minimum supported server
Windows Server 2008 R2 [desktop apps only]

See also

Device Object

Service Object

servicesCollection Object