Whenever I attempt to access the registry using ZwOpenKey I keep getting and error code 0xC000003A back from the call
the following code seems to have the error:
RtlInitUnicodeString(&subKey,L"\Registry\Machine\System\ControlSet001\Services\MyDriverServiceName");
InitializeObjectAttributes(&ObjectAttrib, &subKey, OBJ_KERNEL_HANDLE, NULL, NULL);
ntStatus = ZwOpenKey(&hCapabilityKeyHandle,
KEY_READ | KEY_QUERY_VALUE,
&ObjectAttrib);
ntStatus is 0xC000003A. In ntstatus.h this translates to STATUS_OBJECT_PATH_NOT_FOUND. I have checked the registry using RegEdit and the HKLM\System\ControlSet001\Services\MyDriverServiceName key definitely exists (I put it there).
Anyone here know what I am missing or doing wrong?
I am using Vista and kdmf to write a filter driver.
My function is here:
NTSTATUS
GetDriverSettings(IN PNS_FILTER_SETTINGS FilterSettings)
{
//This routine can only be called at IRQL = PASSIVE_LEVEL
NTSTATUS ntStatus;
OBJECT_ATTRIBUTES ObjectAttrib;
UNICODE_STRING subKey;
UNICODE_STRING DrvSet1;
ULONG Set1 = 0x00000000;
HANDLE hCapabilityKeyHandle = 0;
strcpy(&err[0], TEXT(“No Error”));
RtlInitUnicodeString(&subKey,L"\Registry\Machine\System\ControlSet001\Services\MyDriverServiceName");
InitializeObjectAttributes(&ObjectAttrib, &subKey, OBJ_KERNEL_HANDLE, NULL, NULL);
ntStatus = ZwOpenKey(&hCapabilityKeyHandle,
KEY_READ | KEY_QUERY_VALUE,
&ObjectAttrib);
if ( STATUS_INVALID_HANDLE == ntStatus ) {
strcpy(&err[0], TEXT(“Opening Key Failed: Invlaid Handle”));
}
if ( STATUS_ACCESS_DENIED == ntStatus ) {
strcpy(&err[0], TEXT(“Opening Key Failed: Acess Denied”));
}
if ( !NT_SUCCESS(ntStatus) ) {
sprintf(err, “Opening Key Failed: Error Code 0x%x”, ntStatus);
}
if ( NT_SUCCESS(ntStatus) )
{
OBJECT_ATTRIBUTES objAttribDwordKeyVal;
UNICODE_STRING subValDword;
RtlInitUnicodeString(&DrvSet1,L"MyDWordKey");
ntStatus = ZwQueryValueKey(hCapabilityKeyHandle, &DrvSet1, 0, REG_DWORD, &Set1, sizeof(ULONG));
if ( !NT_SUCCESS(ntStatus) ) {
sprintf(err, “Querying Value Failed: Error Code 0x%x”, ntStatus);
}
//Do my setup here
}
return STATUS_SUCCESS;
}