函数原型如下:
NTSTATUS IoOpenDeviceRegistryKey( IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey );
其中DevInstKeyType为PLUGPLAY_REGKEY_DRIVER时,是操作HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{EF2962F0-0D55-4BFF-B8AA-2221EE8A79B0}\0000
而DevInstKeyType为PLUGPLAY_REGKEY_DEVICE时,是操作HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\Root\ZHANGFANDEVICE\0000\Device Parameters
以下是测试代码:
HANDLE devInstRegKey;
NTSTATUS status = IoOpenDeviceRegistryKey (pdo,
PLUGPLAY_REGKEY_DRIVER ,
STANDARD_RIGHTS_ALL,
&devInstRegKey);
UNICODE_STRING ValueName;
RtlInitUnicodeString(&ValueName, L"MyValue1234");
ULONG Value = 0x12345678;
status = ZwSetValueKey(devInstRegKey, &ValueName, 0, REG_DWORD, &Value, sizeof(ULONG));
if (NT_SUCCESS(status)) {
ZwClose(devInstRegKey);
} else {
KdPrint(("write reg failed")); // handle error.
}