Skip to content

比较注册表键 - RegistryCompareKeys

函数简介

比较两个注册表键的内容,返回比较结果的JSON字符串。

接口名称

RegistryCompareKeys

DLL调用

cpp
int64_t RegistryCompareKeys(int64_t instance, int32_t rootKey1, const char* subKey1, int32_t rootKey2, const char* subKey2);

参数说明

参数名类型说明
instance长整数型OLAPlug对象的指针,由 CreateCOLAPlugInterFace 接口生成。
rootKey1整数型第一个根键类型:0 HKEY_CLASSES_ROOT、1 HKEY_CURRENT_USER、2 HKEY_LOCAL_MACHINE、3 HKEY_USERS、4 HKEY_CURRENT_CONFIG
subKey1字符串第一个子键路径
rootKey2整数型第二个根键类型
subKey2字符串第二个子键路径

示例

SDK 调用

cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
std::string diff = ola.RegistryCompareKeys(1, "Software\\OLAPlug", 1, "Software\\OLAPlugBackup");
csharp
using OLAPlug;

var ola = new OLAPlugServer();
string diff = ola.RegistryCompareKeys(1, @"Software\OLAPlug", 1, @"Software\OLAPlugBackup");
python
from OLAPlugServer import OLAPlugServer

ola = OLAPlugServer()
diff = ola.RegistryCompareKeys(1, r"Software\OLAPlug", 1, r"Software\OLAPlugBackup")
java
import com.olaplug.OLAPlugServer;

OLAPlugServer ola = new OLAPlugServer();
ola.RegistryCompareKeys(1, "Software\\OLAPlug", 1, "Software\\OLAPlugBackup");
cpp
var ola = com("OlaPlug.OlaSoft")
ola.RegistryCompareKeys(1, "Software\\OLAPlug", 1, "Software\\OLAPlugBackup");
vbscript
Set ola = CreateObject("OlaPlug.OlaSoft")
ola.RegistryCompareKeys(1, "Software\\OLAPlug", 1, "Software\\OLAPlugBackup");
text
.局部变量 ola, OLAPlug
ola.创建 ()
ola.RegistryCompareKeys(1, "Software\\OLAPlug", 1, "Software\\OLAPlugBackup");
aardio
import OLAPlugServer;
var ola = OLAPlugServer();
ola.RegistryCompareKeys(1, "Software\\OLAPlug", 1, "Software\\OLAPlugBackup");
text
变量 ola <类型 = OLAPlugServer>
ola = 新建 OLAPlugServer
ola.RegistryCompareKeys(1, "Software\\OLAPlug", 1, "Software\\OLAPlugBackup");
cpp
#include "OLAPlugServer.h"

OLAPlugServer ola;
ola.RegistryCompareKeys(1, "Software\\OLAPlug", 1, "Software\\OLAPlugBackup");

原生 DLL 调用

cpp
long instance = CreateCOLAPlugInterFace();
long ptr = RegistryCompareKeys(instance, 1, "Software\\OLAPlug", 1, "Software\\OLAPlugBackup");
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 RegistryCompareKeys(long ola, int rootKey1, string subKey1, int rootKey2, string subKey2);

long instance = CreateCOLAPlugInterFace();
long ptr = RegistryCompareKeys(instance, 1, @"Software\OLAPlug", 1, @"Software\OLAPlugBackup");
if (ptr != 0) {
    StringBuilder sb = new StringBuilder(GetStringSize(ptr) + 1);
    GetStringFromPtr(ptr, sb, sb.Capacity);
    FreeStringPtr(ptr);
    string diff = 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.RegistryCompareKeys(instance, 1, b"Software\\OLAPlug", 1, b"Software\\OLAPlugBackup")

返回值

长整数型。成功返回JSON字符串指针,包含比较结果;失败返回 0。返回的字符串指针需调用 FreeStringPtr 释放内存。

返回的JSON结构:

json
{
    "equal": true/false,
    "differences": [
        {
            "type": "value_changed|value_added|value_removed|subkey_changed",
            "name": "值或子键名称",
            "value1": "第一个键的值",
            "value2": "第二个键的值"
        }
    ]
}

注意事项

  • 如果两个键完全相同,equal 字段为 truedifferences 数组为空。
  • 比较操作不会修改任何注册表内容。
  • 可用于配置迁移前的验证。