The PcNewRegistryKey function opens or creates a new registry key and creates an IRegistryKey object to represent the key. The caller accesses the key through this object.
PORTCLASSAPI NTSTATUS NTAPI
PcNewRegistryKey(
OUT PREGISTRYKEY *OutRegistryKey,
IN PUNKNOWN OuterUnknown OPTIONAL,
IN ULONG RegistryKeyType,
IN ACCESS_MASK DesiredAccess,
IN PVOID DeviceObject OPTIONAL,
IN PVOID SubDevice OPTIONAL,
IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,
IN ULONG CreateOptions OPTIONAL,
OUT PULONG Disposition OPTIONAL
);
PcNewRegistryKey returns STATUS_SUCCESS if the call was successful. Otherwise, it returns an appropriate error code.
Declared in portcls.h. Include portcls.h.
If the RegistryKeyType parameter's value is GeneralRegistryKey, then the PcNewRegistryKey function either opens an existing key or creates a new key in the registry, as indicated by the value that the function outputs through the Disposition parameter. If the key is of any type other than GeneralRegistryKey, then the function opens an already existing key that was previously created during PnP device enumeration.
The DesiredAccess, ObjectAttributes, CreateOptions, and Disposition parameters take on the values that are defined for the parameters with the same names in the ZwCreateKey call.
The RegistryKeyType parameter should be set to one of the enumeration values shown in the following table.
| RegistryKeyType value | Meaning |
| GeneralRegistryKey | Provide generic access to any key type. Open the specified key if it already exists or create the key if it does not. |
| DeviceRegistryKey | Open an existing key containing device-specific information. The key is located under the key for the device instance specified by DeviceObject. |
| DriverRegistryKey | Open an existing key containing driver-specific information. |
| HwProfileRegistryKey | Open an existing key relative to the current hardware profile containing device or driver information. This allows the driver to access configuration information that is hardware-profile-specific. |
| DeviceInterfaceRegistryKey | Not used with PcNewRegistryKey. See IPort::NewRegistryKey for details. |
For a RegistryKeyType value of GeneralRegistryKey, the caller must provide valid ObjectAttributes and CreateOptions parameter values. For any other RegistryKeyType value, the caller must provide a valid DeviceObject parameter value.
The DesiredAccess parameter is an access-control mask. It specifies the type of access control that the caller needs to have to the new registry key when accessing it through the OutRegistryKey object. This mask should not be confused with the ACL (access control list) that controls access by users to the registry key. When calling PcNewRegistryKey to create a registry key of type GeneralRegistryKey, the ObjectAttributes parameter specifies the key's attributes, including a security descriptor that contains the ACL. However, if the new key is of type GeneralRegistryKey and either the security descriptor pointer in the ObjectAttributes structure is NULL or the ACL pointer in the security descriptor is NULL, then the new key will inherit the parent key’s ACL by default.
If the key is of any type other than GeneralRegistryKey, then the key retains the ACL that PnP assigned to the key when it was created during device enumeration.
The PcNewRegistryKey function is similar to the IPort::NewRegistryKey method except that the device object and port object must be explicitly specified in a PcNewRegistryKey call but are simply implied in a NewRegistryKey call. PcNewRegistryKey is used primarily by adapter drivers. Miniport drivers typically call NewRegistryKey instead.
The OutRegistryKey and OuterUnknown parameters follow the reference-counting conventions for COM objects.
IRegistryKey, ACCESS_MASK, DEVICE_OBJECT, OBJECT_ATTRIBUTES, ZwCreateKey, IPort::NewRegistryKey