注册表

注册表由主键和值组成。主键可以包含主键、值或者两者都有。主键包含的数据有一系列预定义的格式。主键可以包含 主键,所以注册表是典型的层次结构。最高层主键,即根主键,通过他们预定义的数值常数指定。根主键以下的主键和值通过他们的名称来区别。多级主键可以在一个字符串中指定,通过反斜杠/将主键隔开。

查询和修改一个值,必须先打开包含该值的主键,然后对值进行查询或者写入,最后关闭主键。主键和值也可以被枚举,这样应用程序可以确定某个主键包含的内容。注册表中的数据可以按照一系列预定义的数据类型来存储。这些数据类性有:字符串、32位数值,以及无格式的二进制数值。

1.注册表组织

HKEY_LOCAL_MACHINE:存储硬件和驱动程序配置数据

HKEY_CURRENT_USER :存储用户特定的配置数据

HKEY_CLASSES_ROOT:存储类型匹配和OLE配置数据。

2.注册表API

1)打开和创建主键

RegOpenKeyEx();

LONG RegOpenKeyEx( 
  HKEY hKey, 
  LPCWSTR lpSubKey, 
  DWORD ulOptions, 
  REGSAM samDesired, 
  PHKEY phkResult 
); 
Parameters
hKey;根主键常数或者是前面已经打开的主键
[in] Handle to a currently open key or any of the following predefined reserved handle values:
  • HKEY_CLASSES_ROOT
  • HKEY_CURRENT_USER
  • HKEY_LOCAL_MACHINE
  • HKEY_USERS

Windows CE does not support the HKEY_CURRENT_CONFIG, HKEY_PERFORMANCE_DATA, or HKEY_DYN_DATA predefined reserved handle values.

主键和值的名称和大小写无关

lpSubKey;子字符串可以包含多级子键,用反斜杠隔开
[in] Pointer to a null-terminated string containing the name of the subkey to open. If this parameter is NULL or a pointer to an empty string, the function will open a new handle to the key identified by the hKey parameter. In this case, the function will not close the handles previously opened.
ulOptions
[in] Reserved; set to 0.
samDesired
[in] Not supported; set to 0.
phkResult
[out] Pointer to a variable that receives a handle to the opened key. When you no longer need the returned handle, call the RegCloseKey function to close it.
Return Values

ERROR_SUCCESS indicates success. A nonzero error code defined in Winerror.h indicates failure. To get a generic description of the error, call FormatMessage with the FORMAT_MESSAGE_FROM_SYSTEM flag set. The message resource is optional; therefore, if you call FormatMessage it could fail.

打开注册表主键的另外一个方法:RegCreateKeyEx();

This function creates the specified key. If the key already exists in the registry, the function opens it。

LONG RegCreateKeyEx( 
  HKEY hKey, 
  LPCWSTR lpSubKey, 
  DWORD Reserved, 
  LPWSTR lpClass, 
  DWORD dwOptions, 
  REGSAM samDesired, 
  LPSECURITY_ATTRIBUTES lpSecurityAttributes, 
  PHKEY phkResult, 
  LPDWORD lpdwDisposition 
); 
Parameters
hKey
[in] Handle to a currently open key or one of the following predefined reserved handle values:
  • HKEY_CLASSES_ROOT
  • HKEY_CURRENT_USER
  • HKEY_LOCAL_MACHINE
  • HKEY_USERS

Windows CE does not support

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值