主题
注册表模块总览 - Overview
本分类做什么
对 Windows 注册表 进行打开、创建、枚举、读写字符串与整型值、备份恢复、搜索键、读取本机与软件列表等。API 名以 Registry 前缀统一,与 文件 的纯磁盘路径不同。
一、键生命周期
| 接口 | 差异 |
|---|---|
| RegistryOpenKey | 打开已有键,返回句柄。 |
| RegistryCreateKey | 不存在则创建。 |
| RegistryCloseKey | 关闭句柄。 |
| RegistryKeyExists | 存在性探测。 |
| RegistryDeleteKey | 删除子键(权限见详情页)。 |
二、值:字符串与整数
| 类型 | 写 | 读 |
|---|---|---|
| 字符串 | RegistrySetString | RegistryGetString |
| 保护字符串(随机位置) | RegistrySetProtectedValue | RegistryGetProtectedValue |
| 32 位 | RegistrySetDword | RegistryGetDword |
| 64 位 | RegistrySetQword | RegistryGetQword |
| 删除 | RegistryDeleteValue | — |
差异:DWORD 与 QWORD 对应 REG_DWORD / REG_QWORD;勿混用导致截断。
三、枚举
| 接口 | 内容 |
|---|---|
RegistryEnumSubKeys | 子 键 名列表。 |
RegistryEnumValues | 子 值 名列表。 |
四、环境变量与路径
| 接口 | 用途 |
|---|---|
RegistrySetEnvironmentVariable、RegistryGetEnvironmentVariable | 读写 环境变量(作用域见详情页)。 |
RegistryGetUserRegistryPath、RegistryGetSystemRegistryPath | 常用 根路径 快捷方式。 |
五、备份、搜索、比较
| 接口 | 差异 |
|---|---|
RegistryBackupToFile、RegistryRestoreFromFile | 整文件 备份/恢复。 |
RegistrySearchKeys | 按条件 搜索键。 |
RegistryCompareKeys | 两键 差异对比。 |
六、系统信息
| 接口 | 说明 |
|---|---|
RegistryGetInstalledSoftware | 已安装软件列表。 |
RegistryGetWindowsVersion | Windows 版本 信息。 |
七、快速选型
| 需求 | 建议 |
|---|---|
| 读卸载残留 | RegistryOpenKey + RegistryEnumSubKeys |
| 存脚本配置 | 若可写 HKCU,优先 用户键;需管理员 → HKLM(见详情页权限) |
| 迁移机器 | RegistryBackupToFile |
八、注意
- x86/x64 视图、重定向(如 WOW6432Node)以详情页为准。
- 误删系统键可导致 系统无法启动。
