MFC操作注册表
2012-05-26 11:09
411 查看
http://blog.sina.com.cn/s/blog_7c36017b01012mez.html
打开注册表键
LONG RegOpenKeyEx(
HKEY hKey, // handle to open key主键
LPCTSTR lpSubKey, // subkey name子键
DWORD ulOptions, // reserved。必须是0
REGSAM samDesired, // security access mask读写标识
PHKEY phkResult // handle to open key返回的HKEY类型的指针。以后,读写,关闭用这个指针
);
如:
读取注册表
LONG RegQueryValueEx(
HKEY hKey, // handle to key打开注册表指针
LPCTSTR lpValueName, // value name要读取的键名称
LPDWORD lpReserved, // reserved must be NULL. 必须是NULL
LPDWORD lpType, // type buffer,键类型。我最常用REG_SZ,REG_DWORD
LPBYTE lpData, // data buffer。保存查询结果的缓冲区
LPDWORD lpcbData // size of data buffer。缓冲区大小
);
如:
写注册表
LONG RegSetValueEx(
HKEY hKey, // handle to key。打开注册表的指针
LPCTSTR lpValueName, // value name 要写入的键
DWORD Reserved, // reserved 必须是0
DWORD dwType, // value type 写入值类型
CONST BYTE *lpData, // value data 要写入的数据
DWORD cbData // size of value data 。数据SIZE
);
如:
创建一个新键
LONG RegCreateKeyEx(
HKEY hKey, // handle to open key。打开的注册表指针
LPCTSTR lpSubKey, // subkey name。子键名称
DWORD Reserved, // reserved。必须为0
LPTSTR lpClass, // class string。已经存在时用,一般为NULL
DWORD dwOptions, // special options
//默认值REG_OPTION_VOLATILE,保存在注册表,下次开机仍然存在
//REG_OPTION_VOLATILE,保存在内存
//REG_OPTION_BACKUP_RESTORE
REGSAM samDesired, // desired security access。操作权限。一般KEY_ALL_ACCESS,除非有特殊需要,请查阅MSDN
LPSECURITY_ATTRIBUTES lpSecurityAttributes, // inheritance。继承性。一般为NULL
PHKEY phkResult, // key handle 。返回该键值镇。
LPDWORD lpdwDisposition // disposition value buffer
//REG_CREATED_NEW_KEY The key did not exist and was created.
//REG_OPENED_EXISTING_KEY The key existed and was simply opened without being changed.
);
删除一个键
LONG RegDeleteKey(
HKEY hKey, // handle to open key
LPCTSTR lpSubKey // subkey name
);
删除一个键值
LONG RegDeleteValue(
HKEY hKey, // handle to key
LPCTSTR lpValueName // value name。值名称,不是打开的那个指针,是查询到的指针,如果为空RegSetValueEx创建的值将被删除
);
刷新注册表
LONG RegFlushKey(
HKEY hKey // handle to key to write。写入所有的值,在给定的指针
);
导入一个注册表文件
到指定的键下
LONG RegLoadKey(
HKEY hKey, // handle to open key
LPCTSTR lpSubKey, // subkey name
LPCTSTR lpFile // registry file name
);
关闭打开的注册表
LONG RegCloseKey(
HKEY hKey // handle to key to close
);
打开注册表键
LONG RegOpenKeyEx(
HKEY hKey, // handle to open key主键
LPCTSTR lpSubKey, // subkey name子键
DWORD ulOptions, // reserved。必须是0
REGSAM samDesired, // security access mask读写标识
PHKEY phkResult // handle to open key返回的HKEY类型的指针。以后,读写,关闭用这个指针
);
如:
// 打开HKEY_LOCAL_MACHINE主键下的SoftWare\\Knight Studio\\Knight子键 HKEY hKEY; HKEY hKeyRoot = HKEY_LOCAL_MACHINE; long ret0=(::RegOpenKeyEx(hKeyRoot,"SoftWare\\Knight Studio\\Knight",0,KEY_READ,&hKEY)); if(ret0!=ERROR_SUCCESS)//如果无法打开hKEY,则中止程序的执行 { AfxMessageBox("错误:无法打开有关的hKEY"); return; }
读取注册表
LONG RegQueryValueEx(
HKEY hKey, // handle to key打开注册表指针
LPCTSTR lpValueName, // value name要读取的键名称
LPDWORD lpReserved, // reserved must be NULL. 必须是NULL
LPDWORD lpType, // type buffer,键类型。我最常用REG_SZ,REG_DWORD
LPBYTE lpData, // data buffer。保存查询结果的缓冲区
LPDWORD lpcbData // size of data buffer。缓冲区大小
);
如:
// hKEY是上面打开时得到的指针。 LPBYTE getValue = new BYTE[80];//得到的键值 DWORD keyType = REG_SZ;//定义数据类型 DWORD DataLen = 80;//定义数据长度 CString strUser = _T("UserName");//要查询的键名称 long ret1=::RegQueryValueEx(hKEY,strUser,NULL,&keyType,getValue,&DataLen); if(ret1!=ERROR_SUCCESS) { AfxMessageBox("错误:无法查询有关的注册表信息"); return; }
写注册表
LONG RegSetValueEx(
HKEY hKey, // handle to key。打开注册表的指针
LPCTSTR lpValueName, // value name 要写入的键
DWORD Reserved, // reserved 必须是0
DWORD dwType, // value type 写入值类型
CONST BYTE *lpData, // value data 要写入的数据
DWORD cbData // size of value data 。数据SIZE
);
如:
// 写注册表。修改UserName为Knight // 写入CString类型的数据 CString strUser = _T("UserName");//要写入的键名称 LPCTSTR strUserValue = "Knight"; long ret = ::RegSetValueEx(hKEY, strUser, 0, REG_SZ, (const BYTE *) strUserValue, strlen(strUserValue)+1); if(ret1!=ERROR_SUCCESS) { AfxMessageBox("错误:无法查询有关的注册表信息"); return; }
创建一个新键
LONG RegCreateKeyEx(
HKEY hKey, // handle to open key。打开的注册表指针
LPCTSTR lpSubKey, // subkey name。子键名称
DWORD Reserved, // reserved。必须为0
LPTSTR lpClass, // class string。已经存在时用,一般为NULL
DWORD dwOptions, // special options
//默认值REG_OPTION_VOLATILE,保存在注册表,下次开机仍然存在
//REG_OPTION_VOLATILE,保存在内存
//REG_OPTION_BACKUP_RESTORE
REGSAM samDesired, // desired security access。操作权限。一般KEY_ALL_ACCESS,除非有特殊需要,请查阅MSDN
LPSECURITY_ATTRIBUTES lpSecurityAttributes, // inheritance。继承性。一般为NULL
PHKEY phkResult, // key handle 。返回该键值镇。
LPDWORD lpdwDisposition // disposition value buffer
//REG_CREATED_NEW_KEY The key did not exist and was created.
//REG_OPENED_EXISTING_KEY The key existed and was simply opened without being changed.
);
删除一个键
LONG RegDeleteKey(
HKEY hKey, // handle to open key
LPCTSTR lpSubKey // subkey name
);
删除一个键值
LONG RegDeleteValue(
HKEY hKey, // handle to key
LPCTSTR lpValueName // value name。值名称,不是打开的那个指针,是查询到的指针,如果为空RegSetValueEx创建的值将被删除
);
刷新注册表
LONG RegFlushKey(
HKEY hKey // handle to key to write。写入所有的值,在给定的指针
);
导入一个注册表文件
到指定的键下
LONG RegLoadKey(
HKEY hKey, // handle to open key
LPCTSTR lpSubKey, // subkey name
LPCTSTR lpFile // registry file name
);
关闭打开的注册表
LONG RegCloseKey(
HKEY hKey // handle to key to close
);
相关文章推荐
- MFC操作注册表
- MFC注册表操作
- 关于开机启动运行的注册表操作(MFC)
- MFC注册表操作
- MFC操作注册表
- C/C++/VC++/mfc对注册表的操作
- MFC操作注册表常用函数
- MFC注册表操作详解
- MFC 注册表操作
- MFC操作注册表
- MFC操作--数据输出、注册表、文件统计和获取上级目录
- MFC操作注册表
- MFC操作注册表获取USB磁盘代码阅读步骤总结
- 九:[VC++]MFC操作注册表
- MFC注册表操作
- MFC中用c++语言对注册表操作(写、开机自启)
- 编程实现mscomm32写入注册表,解决写入值乱码问题,mfc中操作注册表操作。
- MFC的注册表操作—CRegKey类的使用
- MFC对注册表的操作
- MFC 注册表操作