Opening a device's hardware key

A hardware key is device-specific registry subkey that contains information about the device. You must not directly open a device's hardware key. As with any registry key, the location or format of these keys might change between different versions of Windows.

Note

You should open a device's hardware key only after the corresponding device has been found. For more information about this procedure, see Enumerating Installed Devices.

To open or create a device's hardware key, follow these guidelines:

Note

You must set the parameter where you provide the requested security access to the minimal access permissions that are required. You must not set this parameter to KEY_ALL_ACCESS. For more information about how to specify access permissions for registry access, see Accessing Registry Keys Safely.

  • To open an existing hardware key, use CM_Open_DevNode_Key with a Disposition of RegDisposition_OpenExisting and ulFlags containing CM_REGISTRY_HARDWARE or use SetupDiOpenDevRegKey and KeyType parameter of DIREG_DEV.

  • To create a hardware key, use CM_Open_DevNode_Key with a Disposition of RegDisposition_OpenAlways and ulFlags containing CM_REGISTRY_HARDWARE or use SetupDiCreateDevRegKey and KeyType parameter of DIREG_DEV.

  • Kernel-mode callers should use IoOpenDeviceRegistryKey and set the DevInstKeyType parameter to PLUGPLAY_REGKEY_DEVICE.