阅读:2280回复:2
用ZwOpenKey老是出错!
我的程序需要在响应Deviceiocontrol的时候读注册表,获得一个值:
我这么调用: ULONG value; GetRegValueDword(L"\\Registry\\Machine\\System\\CurrentControlSet\\Services\\mykey", L"test", &value); 其中函数的定义如下: int GetRegValueDword(PCWSTR RegPath,PCWSTR ValueName,PULONG Value) { int ReturnValue = 0; NTSTATUS Status; OBJECT_ATTRIBUTES ObjectAttributes; HANDLE KeyHandle; KEY_VALUE_PARTIAL_INFORMATION *Information; ULONG InformationSize; UNICODE_STRING UnicodeRegPath; UNICODE_STRING UnicodeValueName; RtlInitUnicodeString(&UnicodeRegPath, RegPath); RtlInitUnicodeString(&UnicodeValueName, ValueName); InitializeObjectAttributes(&ObjectAttributes, &UnicodeRegPath, OBJ_CASE_INSENSITIVE, // Flags NULL, // Root directory NULL); // Security descriptor Status = ZwOpenKey(&KeyHandle, KEY_ALL_ACCESS, &ObjectAttributes); if (Status != STATUS_SUCCESS) { return 0; } InformationSize = sizeof(Information) + sizeof(ULONG); Information = (KEY_VALUE_PARTIAL_INFORMATION*)ExAllocatePoolWithTag(PagedPool, InformationSize,'ISmD'); // DmSI if (Information == NULL) { ZwClose(KeyHandle); return 0; } Status = ZwQueryValueKey(KeyHandle, &UnicodeValueName, KeyValuePartialInformation, Information, sizeof(Information), &InformationSize); if (Status == STATUS_SUCCESS) { if (Information->Type == REG_DWORD && Information->DataLength == sizeof(ULONG)) { RtlCopyMemory(Value, Information->Data, sizeof(ULONG)); ReturnValue = 1; } } ExFreePool(Information); ZwClose(KeyHandle); return ReturnValue; } 经过跟踪发现,ZwopenKey不能打开注册表,请问为什么? |
|
沙发#
发布于:2001-11-12 14:56
可能是CurrentControlSet还没有映射.
|
|
|
板凳#
发布于:2005-06-16 16:48
有没有大侠能给几个读写注册表成功的例子啊,先谢啦
|
|
|