主题
比较注册表键 - RegistryCompareKeys
函数简介
比较两个注册表键的内容,返回比较结果的JSON字符串。
接口名称
RegistryCompareKeysDLL调用
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");go
import "github.com/ola/olaplug/olaplug"
ola, _ := olaplug.NewOLAPlugServer("OLAPlug_x64.dll")
defer ola.ReleaseObj()
diff := ola.RegistryCompareKeys(1, "Software\\OLAPlug", 1, "Software\\OLAPlugBackup")rust
use olaplug::OLAPlugServer;
let ola = OLAPlugServer::new("OLAPlug_x64.dll").unwrap();
let diff = ola.registry_compare_keys(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")返回值
| 返回值 | 说明 |
|---|---|
非 0 | 成功,返回 JSON字符串指针,包含比较结果。 |
0 | 失败。 |
json
{
"equal": true/false,
"differences": [
{
"type": "value_changed|value_added|value_removed|subkey_changed",
"name": "值或子键名称",
"value1": "第一个键的值",
"value2": "第二个键的值"
}
]
}注意事项
| 项目 | 说明 |
|---|---|
| 如果两个键完全相同 | 如果两个键完全相同,equal 字段为 true,differences 数组为空。 |
| 比较操作不会修改任何注册表内容 | 比较操作不会修改任何注册表内容。 |
| 可用于配置迁移前的验证 | 可用于配置迁移前的验证。 |
