RegOpenKeyEx:该函数用来打开特定的注册表键,注册表键值是不区分大小写的。
该远程调用接口也存在,函数名称为CeRegOpenKeyEx
LONG RegOpenKeyEx(
HKEY hKey,
LPCWSTR lpSubKey,
DWORD ulOptions,
REGSAM samDesired,
PHKEY phkResult
);
Parameters
参数
hKey
入参,标识当前被 RegCreateKeyEx 或RegOpenKeyEx打开的注册表键的句柄,或者是以下预定义的句柄
HKEY_CLASSES_ROOT
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
lpSubKey
入参,该参数指向一个字符串,该字符串用来保存将要打开的注册表名称。如果这个参数是空,或者是一个指向空串的指针,该函数将会打开一个由hKey所定义的键,在此种情况下,该函数不会关闭舷墙已经打开的句柄。
ulOptions
入参,保留,设置为0
samDesired
入参。标识打开注册表的权力,如果该参数的安全描述符不容许当前进程访问注册表,则该函数会返回失败。详细的安全描述见下表:
KEY_ALL_ACCESS (0xF003F) | Combines the STANDARD_RIGHTS_REQUIRED, KEY_QUERY_VALUE, KEY_SET_VALUE, KEY_CREATE_SUB_KEY, KEY_ENUMERATE_SUB_KEYS, KEY_NOTIFY, and KEY_CREATE_LINK access rights. |
KEY_CREATE_LINK (0x0020) | Reserved for system use. |
KEY_CREATE_SUB_KEY (0x0004) | Required to create a subkey of a registry key. |
KEY_ENUMERATE_SUB_KEYS (0x0008) | Required to enumerate the subkeys of a registry key. |
KEY_EXECUTE (0x20019) | Equivalent to KEY_READ. |
KEY_NOTIFY (0x0010) | Required to request change notifications for a registry key or for subkeys of a registry key. |
KEY_QUERY_VALUE (0x0001) | Required to query the values of a registry key. |
KEY_READ (0x20019) | Combines the STANDARD_RIGHTS_READ, KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, and KEY_NOTIFY values. |
KEY_SET_VALUE (0x0002) | Required to create, delete, or set a registry value. |
KEY_WOW64_32KEY (0x0200) | Indicates that an application on 64-bit Windows should operate on the 32-bit registry view. For more information, see Accessing an Alternate Registry View. |
This flag must be combined using the OR operator with the other flags in this table that either query or access registry values. | |
KEY_WOW64_64KEY (0x0100) | Indicates that an application on 64-bit Windows should operate on the 64-bit registry view. For more information, see Accessing an Alternate Registry View. |
This flag must be combined using the OR operator with the other flags in this table that either query or access registry values. | |
KEY_WRITE (0x20006) | Combines the STANDARD_RIGHTS_WRITE, KEY_SET_VALUE, and KEY_CREATE_SUB_KEY access rights. |
phkResult
出参,指向一个变量的指针,该变量用来保存打开注册表键的句柄。如果不再使用返回的句柄,则调用RegCloseKey来关闭它。
返回值:
ERROR_SUCCESS表示该函数执行成功,非零值表示该函数执行失败。想要获得错误描述,调用FormatMessage函数,并传入FORMAT_MESSAGE_FROM_SYSTEM参数。
注意:
与RegCreateKeyEx不同,当要打开的键不存在时,RegOpenKeyEx函数不创建新键。
Requirements
Client | Requires Windows "Longhorn", Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, or Windows 95. |
---|---|
Server | Requires Windows Server "Longhorn", Windows Server 2003, Windows 2000 Server, or Windows NT Server. |
Header | Declared in Winreg.h; include Windows.h. |
Library | Link to Advapi32.lib. |
DLL | Requires Advapi32.dll. |
Unicode | Implemented as RegOpenKeyExW (Unicode) and RegOpenKeyExA (ANSI). Note that Unicode support on Windows Me/98/95 requires Microsoft Layer for Unicode. |