SetupDiSetDeviceProperty function

The SetupDiSetDeviceProperty function sets a device instance property.


BOOL SetupDiSetDeviceProperty(
  _In_           HDEVINFO         DeviceInfoSet,
  _In_           PSP_DEVINFO_DATA DeviceInfoData,
  _In_     const DEVPROPKEY       *PropertyKey,
  _In_           DEVPROPTYPE      PropertyType,
  _In_opt_ const PBYTE            PropertyBuffer,
  _In_           DWORD            PropertyBufferSize,
  _In_           DWORD            Flags


DeviceInfoSet [in]

A handle to a device information set. This device information set contains a device information element that represents the device instance for which to set a device instance property.

DeviceInfoData [in]

A pointer to the SP_DEVINFO_DATA structure that identifies the device instance for which to set a device instance property.

PropertyKey [in]

A pointer to a DEVPROPKEY structure that represents the device property key of the device instance property to set.

PropertyType [in]

A DEVPROPTYPE-typed value that represents the property-data-type identifier for the device instance property. For more information, see the Remarks section later in this topic.

PropertyBuffer [in, optional]

A pointer to a buffer that contains the device instance property value. If the property is being deleted or set to a NULL value, this pointer must be NULL, and PropertyBufferSize must be set to zero.

PropertyBufferSize [in]

The size, in bytes, of the PropertyBuffer buffer. If PropertyBuffer is NULL, PropertyBufferSize must be set to zero.

Flags [in]

This parameter must be set to zero.

Return value

The function returns TRUE if it is successful. Otherwise, it returns FALSE, and the logged error can be retrieved by calling GetLastError.

The following table includes some of the more common error codes that this function might log.

Return codeDescription

The value of Flags is not zero.


The device information set that is specified by DevInfoSet is not valid.


A supplied parameter is not valid. One possibility is that the device information element is not valid.


The property key that is supplied by PropertyKey is not valid or the property is not writable.


The property-data-type identifier that is supplied by PropertyType, or the property value that is supplied by PropertyBuffer, is not valid.


A user buffer is not valid. One possibility is that PropertyBuffer is NULL, and PropertyBufferSize is not zero.


The device instance that is specified by DevInfoData does not exist.


An internal data buffer that was passed to a system call was too small.


There was not enough system memory available to complete the operation.


An unspecified internal element was not found. One possibility is that the property to be deleted does not exist.


The caller does not have Administrator privileges.



SetupDiSetDeviceProperty is part of the unified device property model.

SetupAPI supports only a Unicode version of SetupDiSetDeviceProperty.

A caller of SetupDiSetDeviceProperty must be a member of the Administrators group to set a device instance property.

SetupDiSetDeviceProperty enforces requirements on the property-data-type identifier and the property value.

To obtain the device property keys for the instance device properties that are set for a device, call SetupDiGetDevicePropertyKeys.

To retrieve a device instance property, call SetupDiGetDeviceProperty.


Target platform

For universal, call CM_Set_DevNode_Property


Available in Windows Vista and later versions of Windows.


Setupapi.h (include Setupapi.h)



See also




Send comments about this topic to Microsoft