枚举子键 - RegistryEnumSubKeys
函数简介
枚举当前注册表键下的所有子键名称,返回JSON数组格式。
接口名称
RegistryEnumSubKeys
DLL调用
int64_t RegistryEnumSubKeys(int64_t instance, int64_t key)
参数定义:
instance(长整型数): OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。key(长整型数): 注册表键句柄,由 RegistryOpenKey 或 RegistryCreateKey 返回
示例:
// 创建OLA对象
int64_t instance = CreateCOLAPlugInterFace();
// 打开注册表键
int64_t key = RegistryOpenKey(instance, 1, "Software\\Microsoft\\Windows\\CurrentVersion");
if (key != 0) {
// 枚举所有子键
int64_t jsonPtr = RegistryEnumSubKeys(instance, key);
if (jsonPtr != 0) {
const char* json = (const char*)jsonPtr;
printf("子键列表: %s\n", json);
// 输出示例: ["Uninstall","Run","RunOnce","Explorer"]
// 解析JSON数组,遍历每个子键
// 可以使用JSON解析库处理返回的数据
// 释放字符串内存
FreeStringPtr(instance, jsonPtr);
} else {
printf("没有子键或枚举失败\n");
}
// 关闭注册表键
RegistryCloseKey(instance, key);
}
// 释放资源
DestroyCOLAPlugInterFace(instance);
返回值
长整型数:
- 成功: 返回包含所有子键名称的JSON数组字符串句柄,例如
["SubKey1","SubKey2"] - 失败或无子键: 返回 0 或空数组
[]
注意事项
- 返回的字符串句柄需使用 FreeStringPtr 释放
- 返回的是JSON数组格式,需要解析后使用
- 仅返回直接子键名称,不包含子键的子键
- 如果键下没有子键,返回空数组
[] - 子键名称按字母顺序排列
