c++ - NtEnumerateKey() 的 KeyInformation 参数

标签 c++ c windows delphi winapi

我很想知道 KeyInformation参数应传递给 NtEnumerateKey() .当我运行以下代码时,NtEnumerateKey()返回 NTSTATUS = 0xC000000D错误消息 “将无效参数传递给服务或函数。”

我用的是Windows 7,虽然下面的代码是用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()返回 STATUS_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,您会看到

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 个中的一个

关于c++ - NtEnumerateKey() 的 KeyInformation 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12756751/

相关文章:

c++ - 如何找到 4 个邻居拉普拉斯算子的卷积;这个程序有什么错误吗?

c++ - SQRT 对比 RSQRT 对比 SSE _mm_rsqrt_ps 基准

c++ - 在 Windows 中使用 MinGW 的谷歌 Protocol Buffer

c++ - 读取文件十六进制数据并存储到 C++ 中的字符串二维数组中

c - 用 C 语言编写的简单变更程序;不明白初始化

c++ - 如何在 Windows 和 Mac 中构建 "Auto Detect Proxy Settings"

java - 如何在不提示用户名/密码的情况下访问 Windows 上的共享文件夹?

c - 基于枚举的静态数组 : C header

c - 如果数组大小只能是一个常量值,那么 char d_name[...] 是什么意思?

windows - 如何从启用了 "Run as Administrator"的基于 WiX 的安装程序安装桌面快捷方式(到批处理文件)?