Skip to content

搜索注册表键 - RegistrySearchKeys

函数简介

在注册表中搜索匹配指定模式的键,支持通配符和递归搜索。

接口名称

RegistrySearchKeys

DLL调用

cpp
int64_t RegistrySearchKeys(int64_t instance, int32_t rootKey, const char* searchPath, const char* searchPattern, int32_t recursive);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
rootKey整数型根键类型:0 HKEY_CLASSES_ROOT、1 HKEY_CURRENT_USER、2 HKEY_LOCAL_MACHINE、3 HKEY_USERS、4 HKEY_CURRENT_CONFIG。
searchPath字符串搜索起始路径。
searchPattern字符串搜索模式,支持通配符 *(匹配任意多个字符)和 ?(匹配单个字符)。
recursive整数型是否递归搜索。1 递归搜索所有子键,0 仅搜索当前层级。

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
std::string result = ola.RegistrySearchKeys(1, "Software", "OLAPlug", 1);
csharp
using OLAPlug;

var ola = new OLAPlugServer();
string result = ola.RegistrySearchKeys(1, "Software", "OLAPlug", 1);
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
result = ola.RegistrySearchKeys(1, "Software", "OLAPlug", 1)
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
ola.RegistrySearchKeys(1, "Software", "OLAPlug", 1);
go
import "github.com/ola/olaplug/olaplug"

ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
result := ola.RegistrySearchKeys(1, "Software", "OLAPlug", 1)
rust
use olaplug::OLAPlugServer;

let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let result = ola.registry_search_keys(1, "Software", "OLAPlug", 1);
cpp
var ola = com("OlaPlug.OlaSoft")
ola.RegistrySearchKeys(1, "Software", "OLAPlug", 1);
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ola.RegistrySearchKeys(1, "Software", "OLAPlug", 1);
text
.局部变量 ola, OLAPlug
ola.创建 ()
ola.RegistrySearchKeys(1, "Software", "OLAPlug", 1);
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
ola.RegistrySearchKeys(1, "Software", "OLAPlug", 1);
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
ola.RegistrySearchKeys(1, "Software", "OLAPlug", 1);
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
ola.RegistrySearchKeys(1, "Software", "OLAPlug", 1);

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long ptr = RegistrySearchKeys(instance, 1, "Software", "OLAPlug", 1);
if (ptr != 0) {
    char buffer[4096] = {0};
    GetStringFromPtr(ptr, buffer, sizeof(buffer));
    FreeStringPtr(ptr);
}
csharp
using System.Runtime.InteropServices;
using System.Text;

[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringFromPtr(long ptr, StringBuilder lpString, int size);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int FreeStringPtr(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern int GetStringSize(long ptr);
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long CreateCOLAPlugInterFace();
[DllImport("OLAPlug_x64.dll", CallingConvention = CallingConvention.StdCall)]
static extern long RegistrySearchKeys(long ola, int rootKey, string basePath, string keyword, int maxResults);

long instance = CreateCOLAPlugInterFace();
long ptr = RegistrySearchKeys(instance, 1, "Software", "OLAPlug", 1);
if (ptr != 0) {
    StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
    GetStringFromPtr(ptr, sb, sb.Capacity);
    FreeStringPtr(ptr);
    string result = sb.ToString();
}
python
from ctypes import CDLL, c_int, c_int64

ola = CDLL("OLAPlug_x64.dll")
ola.CreateCOLAPlugInterFace.restype = c_int64
instance = ola.CreateCOLAPlugInterFace()
ptr = ola.RegistrySearchKeys(instance, 1, b"Software", b"OLAPlug", 1)

返回值

返回值说明
(返回值)长整数型。成功返回JSON数组字符串指针,包含匹配的键路径,例如 ["path1","path2"];失败或无匹配返回 0 或空数组 []。返回的字符串指针需调用 FreeStringPtr 释放内存。

注意事项

项目说明
搜索模式不区分大小写搜索模式不区分大小写。
递归搜索可能耗时较长递归搜索可能耗时较长,建议缩小搜索范围。
路径返回的路径为完整的子键路径。