C++ NtEnumerateKey()的KeyInformation参数
我很想知道C++ NtEnumerateKey()的KeyInformation参数,c++,c,windows,delphi,winapi,C++,C,Windows,Delphi,Winapi,我很想知道KeyInformation参数应该如何传递给NtEnumerateKey()。运行以下代码时,NtEnumerateKey()返回NTSTATUS=0xc00000d,并显示错误消息“向服务或函数传递了无效参数。” 我正在使用Windows7。虽然下面的代码使用Delphi语言,但您也可以用C语言回答我的问题。我的问题不是特定于编程语言的 type KEY_NAME_INFORMATION = record NameLength: ULONG; Name: arr
KeyInformation
参数应该如何传递给NtEnumerateKey()
。运行以下代码时,NtEnumerateKey()
返回NTSTATUS=0xc00000d
,并显示错误消息“向服务或函数传递了无效参数。”
我正在使用Windows7。虽然下面的代码使用Delphi语言,但您也可以用C语言回答我的问题。我的问题不是特定于编程语言的
type
KEY_NAME_INFORMATION = record
NameLength: ULONG;
Name: array[0..254] of WCHAR;
end;
PKEY_NAME_INFORMATION = ^KEY_NAME_INFORMATION;
var
iNtStatus: LONG;
hKeyResult: THandle;
KeyNameInfo: KEY_NAME_INFORMATION;
iResultLen: ULONG;
iNtStatus := NtOpenKey(@hKeyResult, (KEY_ENUMERATE_SUB_KEYS) and not
SYNCHRONIZE, @rObjAttrs);
if hKeyResult = 0 then Exit;
iNtStatus := NtEnumerateKey(hKeyResult,
0,
KeyNameInformation,
@KeyNameInfo, // I'm asking about this parameter,
SizeOf(KEY_NAME_INFORMATION), // and also this parameter
@iResultLen);
更新:奇怪的事情
如果我传递的是KeyBasicInformation
而不是KeyNameInformation
,NtEnumerateKey()
返回状态\u SUCCESS
。NtEnumerateKey()
不支持KeyNameInformation
type
KEY_BASIC_INFORMATION = record
LastWriteTime: LARGE_INTEGER;
TitleIndex: ULONG;
NameLength: ULONG;
Name: array[0..254] of WCHAR;
end;
PKEY_BASIC_INFORMATION = ^KEY_BASIC_INFORMATION;
var
KeyBasicInfo: KEY_BASIC_INFORMATION;
iNtStatus := NtEnumerateKey(hKeyResult,
0,
KeyBasicInformation, // Note this!
@KeyBasicInfo, // Note this!
SizeOf(KEY_BASIC_INFORMATION), // Note this!
@iResultLen);
如果您查看Zw(Nt for usermode)EnumerateKey的文档,您将看到
NTSTATUS ZwEnumerateKey(
_In_ HANDLE KeyHandle,
_In_ ULONG Index,
_In_ KEY_INFORMATION_CLASS KeyInformationClass,
_Out_opt_ PVOID KeyInformation,
_In_ ULONG Length,
_Out_ PULONG ResultLength
);
KeyInformationClass [in]
Specifies a KEY_INFORMATION_CLASS enumeration value that determines the type of information to be received by the KeyInformation buffer. Set KeyInformationClass to one of the following values:
KeyBasicInformation
KeyFullInformation
KeyNodeInformation
If any value not in this list is specified, the routine returns error code STATUS_INVALID_PARAMETER.
如果你往下看KeyInformationClass,你会发现
NTSTATUS ZwEnumerateKey(
_In_ HANDLE KeyHandle,
_In_ ULONG Index,
_In_ KEY_INFORMATION_CLASS KeyInformationClass,
_Out_opt_ PVOID KeyInformation,
_In_ ULONG Length,
_Out_ PULONG ResultLength
);
KeyInformationClass [in]
Specifies a KEY_INFORMATION_CLASS enumeration value that determines the type of information to be received by the KeyInformation buffer. Set KeyInformationClass to one of the following values:
KeyBasicInformation
KeyFullInformation
KeyNodeInformation
If any value not in this list is specified, the routine returns error code STATUS_INVALID_PARAMETER.
您需要使用这3个类中的一个是,但是
键信息类
是一种枚举类型。当KeyInformationClass
参数设置为KeyNameInformation
时,下一个参数(KeyInformation
)必须是指向KEY\u NAME\u INFORMATION
结构类型的变量的指针。@Astaroth我已经更改了我的回答,我是多么仓促,没有阅读你引用的文本。谢谢@MMavipc。