使用 WdfRegistryOpenKey 函数在 umdf2 中创建注册表项时访问被拒绝
Access denied when using WdfRegistryOpenKey function to create registry keys in umdf2
在我的 WDF 驱动程序中,我想将一些用于特定设备的自定义数据保存到注册表中。但我不能使用 WdfRegistryCreateKey() function provided by umdf2 to create a new key under "hardware_key\Device Parameters" on windows10 1909 platform. The error code is "Access Denied". And I have opened the parent key correctly in READ_KEY mask(if not READ_KEY mask, WdfDeviceOpenRegistryKey() 将 return STATUS_INVALID_PARAMETER 指示访问权限不足)。如何解决这个问题?
提前致谢。
// create subkey function definition
NTSTATUS registry_create_key(WDFKEY parent_key, PUNICODE_STRING key_str,
WDFKEY* key)
{
NTSTATUS status;
WDFKEY new_key;
status = WdfRegistryCreateKey(parent_key, key_str, KEY_CREATE_SUB_KEY,
REG_OPTION_NON_VOLATILE, NULL, WDF_NO_OBJECT_ATTRIBUTES,
&new_key);
if (!NT_SUCCESS(status)) {
return status;
}
if (key)
*key = new_key;
else
WdfRegistryClose(new_key);
return status;
}
// open parent key, I have removed the return value judgment for brevity
status = WdfDeviceOpenRegistryKey(
DeviceContext->Device,
PLUGPLAY_REGKEY_DEVICE,
KEY_READ,
WDF_NO_OBJECT_ATTRIBUTES,
&hkey);
// The key name I want to create
UNICODE_STRING myKeyStr;
RtlInitUnicodeString(
&myKeyStr,
L"myKeyStr"
);
// Call the subkey create function
status = registry_create_key(hkey, &myKeyStr, &subkey);
WdfRegistryClose(subkey);
您正在打开用于 KEY_READ
访问的父项,然后尝试在其下创建一个子项。您需要使用 KEY_CREATE_SUB_KEY
访问权限打开父密钥。
在我的 WDF 驱动程序中,我想将一些用于特定设备的自定义数据保存到注册表中。但我不能使用 WdfRegistryCreateKey() function provided by umdf2 to create a new key under "hardware_key\Device Parameters" on windows10 1909 platform. The error code is "Access Denied". And I have opened the parent key correctly in READ_KEY mask(if not READ_KEY mask, WdfDeviceOpenRegistryKey() 将 return STATUS_INVALID_PARAMETER 指示访问权限不足)。如何解决这个问题?
提前致谢。
// create subkey function definition
NTSTATUS registry_create_key(WDFKEY parent_key, PUNICODE_STRING key_str,
WDFKEY* key)
{
NTSTATUS status;
WDFKEY new_key;
status = WdfRegistryCreateKey(parent_key, key_str, KEY_CREATE_SUB_KEY,
REG_OPTION_NON_VOLATILE, NULL, WDF_NO_OBJECT_ATTRIBUTES,
&new_key);
if (!NT_SUCCESS(status)) {
return status;
}
if (key)
*key = new_key;
else
WdfRegistryClose(new_key);
return status;
}
// open parent key, I have removed the return value judgment for brevity
status = WdfDeviceOpenRegistryKey(
DeviceContext->Device,
PLUGPLAY_REGKEY_DEVICE,
KEY_READ,
WDF_NO_OBJECT_ATTRIBUTES,
&hkey);
// The key name I want to create
UNICODE_STRING myKeyStr;
RtlInitUnicodeString(
&myKeyStr,
L"myKeyStr"
);
// Call the subkey create function
status = registry_create_key(hkey, &myKeyStr, &subkey);
WdfRegistryClose(subkey);
您正在打开用于 KEY_READ
访问的父项,然后尝试在其下创建一个子项。您需要使用 KEY_CREATE_SUB_KEY
访问权限打开父密钥。