Expand Minimize

IoOpenDeviceRegistryKey routine

The IoOpenDeviceRegistryKey routine returns a handle to a device-specific or a driver-specific registry key for a particular device instance.


NTSTATUS IoOpenDeviceRegistryKey(
  _In_  PDEVICE_OBJECT DeviceObject,
  _In_  ULONG          DevInstKeyType,
  _In_  ACCESS_MASK    DesiredAccess,
  _Out_ PHANDLE        DevInstRegKey


DeviceObject [in]

Pointer to the PDO of the device instance for which the registry key is to be opened.

DevInstKeyType [in]

Specifies flags indicating whether to open a device-specific hardware key or a driver-specific software key. The flags also indicate whether the key is relative to the current hardware profile. For more information about hardware and software keys, see Registry Keys for Drivers.

The flags are defined as follows:


Open the Device Parameters subkey under the device's hardware key. The key is located under the key for the device instance specified by DeviceObject. This flag cannot be specified with PLUGPLAY_REGKEY_DRIVER.


Open a software key for storing driver-specific information. This flag cannot be specified with PLUGPLAY_REGKEY_DEVICE.


Open a key relative to the current hardware profile for device or driver information. This allows the driver to access configuration information that is hardware-profile-specific. The caller must specify either PLUGPLAY_REGKEY_DEVICE or PLUGPLAY_REGKEY_DRIVER with this flag.

DesiredAccess [in]

Specifies the ACCESS_MASK value that represents the access the caller needs to the key. See the ZwCreateKey routine for a description of each KEY_XXX access right.

DevInstRegKey [out]

Pointer to a caller-allocated buffer that, on successful return, contains a handle to the requested registry key.

Return value

IoOpenDeviceRegistryKey returns STATUS_SUCCESS if the call was successful. Possible error return values include the following.

Return codeDescription

Possibly indicates that the caller specified an illegal set of DevInstKeyType flags.


Possibly indicates that the DeviceObject is not a valid PDO.



The driver must call ZwClose to close the handle returned from this routine when access is no longer required.

The registry keys opened by this routine are nonvolatile.

User-mode setup applications, such as class installers, can access these registry keys using device installation functions such as SetupDiOpenDevRegKey.

To create registry keys, use INF AddReg directives in an INF file or use SetupDiCreateDevRegKey in a setup application.

Callers of IoOpenDeviceRegistryKey must be running at IRQL = PASSIVE_LEVEL in the context of a system thread.


Target platform



Available starting with Windows 2000.


Wdm.h (include Wdm.h, Ntddk.h, or Ntifs.h)




PASSIVE_LEVEL (see Remarks section)

DDI compliance rules

PowerIrpDDis, HwStorPortProhibitedDDIs

See also




Send comments about this topic to Microsoft

© 2015 Microsoft