Accessing Device Properties
You must not discover or change device properties by directly accessing registry keys. Registry keys do not contain required information to discover or change device properties. In addition, the location, format, and meaning of these keys might change between different versions of Windows.
The SetupAPI functions provide consistent behavior and enforce access permissions to protect device properties. Starting with Windows Vista, device properties that have restricted write access also have restricted read access.
To safely access device properties, follow these guidelines:
For user-mode applications, follow these steps:
For more information about device instance properties on Windows Vista and later versions of Windows, see Accessing Device Instance Properties (Windows Vista and Later).
Note Starting with Windows Vista, some device properties are reserved by the operating system. For more information, see Modifying Device Properties.
On Windows 2000, Windows XP, and Windows Server 2003, use SetupDiGetDeviceRegistryProperty to retrieve device properties, and use SetupDiSetDeviceRegistryProperty with SPDRP_Xxx property codes to set device properties.
For more information about device instance properties on Windows 2000, Windows XP, and Windows Server 2003, see Accessing Device Instance SPDRP_Xxx Properties.
Use persistent storage within the registry for custom settings of devices that are physically present and for those that are not. In this case, you must create your own set of registry keys and values. To do this, use SetupDiCreateDevRegKey (to create a new registry key) or use SetupDiOpenDevRegKey (to open an existing registry key). In these functions, the KeyType parameter is used to specify a hardware key (DIREG_DEV) or software key (DIREG_DRV) for the device.
Note Hardware keys persist in the registry until the device is uninstalled. Software keys can be moved or cleared by the device installation components during a driver upgrade
To save the custom settings, use RegCloseKey after the registry key has been created or opened.
For kernel-mode drivers, use IoGetDeviceProperty to access device properties.