原文来自MSDN Library for Visual Studio 2008 SP1,翻译部分仅为个人观点,想要看更多信息请看MSDN,如有版权问题请联系QQ 643166601,邮件[email protected]
RegCreateKeyEx Function
Creates the specified registry key. If the key already exists, the function opens it. Note that key names are not case sensitive.
创建指定的注册表键。如果这个注册表键已经存在注册表中,这个函数打开它。注意:这个键名是不区分大小写的。
To perform transacted registry operations on a key, call the RegCreateKeyTransacted function.
去执行注册表操作在一个键上,调用这个RegCreateKeyTransacted函数。
Syntax
LONG WINAPI RegCreateKeyEx(
__in HKEY hKey,
__in LPCTSTR lpSubKey,
__reserved DWORD Reserved,
__in_opt LPTSTR lpClass,
__in DWORD dwOptions,
__in REGSAM samDesired,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
__out PHKEY phkResult,
__out_opt LPDWORD lpdwDisposition
);
Parameters
hKey
A handle to an open registry key. The calling process must have KEY_CREATE_SUB_KEY access to the key. For more information, see Registry Key Security and Access Rights.
一个句柄去打开注册表键。调用进程必须访问 KEY_CREATE_SUB_KEY 这个键。更多的信息,看Registry Key Security and Access Rights。
This handle is returned by the RegCreateKeyEx or RegOpenKeyEx function, or it can be one of the following predefined keys:
这个句柄是被返回来自RegCreateKeyEx或RegOpenKeyEx函数,或者它是在一个提前定义的键。
HKEY_CLASSES_ROOT
HKEY_CURRENT_CONFIG
HKEY_CURRENT_USER
HKEY_LOCAL_MACHINE
HKEY_USERS
lpSubKey
The name of a subkey that this function opens or creates. The subkey specified must be a subkey of the key identified by the hKey parameter; it can be up to 32 levels deep in the registry tree. For more information on key names, see Structure of the Registry.
这个名字是子键这个函数打开或者创建的。这个子键必须是一个唯一的子键通过hKey参数;它可以是32层深的注册表树。更多的信息在注册表名,看Structure of the Registry。
This parameter cannot be NULL.
这个参数不能是NULL。
Reserved
This parameter is reserved and must be zero.
这个参数是被保留的必须是0。
lpClass
The class (object type) of this key. This parameter may be ignored. This parameter can be NULL.
这个键是类(对象类型)。这个参数可以被忽略。这个参数可以是NULL。
This parameter is used for both local and remote registry keys.
这个参数是被用来处理本地和远程注册表键的。
dwOptions
This parameter can be one of the following values.
这个参数可以是下面的一个值。
Value Meaning
REG_OPTION_BACKUP_RESTORE
0x00000004L
If this flag is set, the function ignores the samDesired parameter and attempts to open the key with the access required to backup or restore the key. If the calling thread has the SE_BACKUP_NAME privilege enabled, the key is opened with the ACCESS_SYSTEM_SECURITY and KEY_READ access rights. If the calling thread has the SE_RESTORE_NAME privilege enabled, the key is opened with the ACCESS_SYSTEM_SECURITY and KEY_WRITE access rights. If both privileges are enabled, the key has the combined access rights for both privileges. For more information, see Running with Special Privileges.
如果这个flag是设置的,这个函数忽略samDesired参数和尝试去打开这个件和这个访问请求去备份或者存储这个键。如果调用线程已经有 SE_BACKUP_NAME 权限,这个键将被打开和 ACCESS_SYSTEM_SECURITY 和 KEY_READ 访问权利。 如果抵用线程已经有 SE_RESTORE_NAME 权限, 这个键将被打开和 ACCESS_SYSTEM_SECURITY 和 KEY_WRITE 访问权利。如果两个权限都已经有了,这个键有组合访问权利的权限。更多信息,看 Running with Special Privileges。
REG_OPTION_CREATE_LINK
0x00000002L
This key is a symbolic link. The target path is assigned to the L"SymbolicLinkValue" value of the key. The target path must be an absolute registry path.
这个键是一个象征性的链接。这是目标路径将这个键赋值为L"SymbolicLinkValue".这个目标路径必须是一个绝对的注册表路径
Registry symbolic links should be used only when absolutely necessary for application compatibility.
注册表象征性的连接应该被用来只有当应用适合绝对必要的情况。
REG_OPTION_NON_VOLATILE
0x00000000L
This key is not volatile; this is the default. The information is stored in a file and is preserved when the system is restarted. The RegSaveKey function saves keys that are not volatile.
这个键是不易改变的,这是默认值。这个信息是存储在一个文件和被保存在系统被重启的。这个 RegSaveKey 函数保存键是不易改变的。
REG_OPTION_VOLATILE
0x00000001L
All keys created by the function are volatile. The information is stored in memory and is not preserved when the corresponding registry hive is unloaded. For HKEY_LOCAL_MACHINE, this occurs when the system is shut down. For registry keys loaded by the RegLoadKey function, this occurs when the corresponding RegUnLoadKey is performed. The RegSaveKey function does not save volatile keys. This flag is ignored for keys that already exist.
所有的键被创建通过用这个函数是容易的。这个信息是存储在内存和不被保存的当这个相对注册表的存储是未加载的。如 HKEY_LOCAL_MACHINE ,当前发生的 当这个系统关闭。 如注册表键加载通过 RegLoadKey函数, 这个当前键相对的 RegUnLoadKey 函数被执行。这个 RegSaveKey函数不能保存这个容易的键。这个标记是被忽略的这个键已经存在。
samDesired
A mask that specifies the access rights for the key. For more information, see Registry Key Security and Access Rights.
一个掩盖指定键的访问权限。更的信息,看 Key Security and Access Rights。
lpSecurityAttributes
A pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned handle can be inherited by child processes. If lpSecurityAttributes is NULL, the handle cannot be inherited.
一个指针指向 SECURITY_ATTRIBUTES结构体那个做出决定那个被返回的句柄可能是被继承给子继承。如果lpSecurityAttributes是NULL,这个句柄不能被继承。
The lpSecurityDescriptor member of the structure specifies a security descriptor for the new key. If lpSecurityAttributes is NULL, the key gets a default security descriptor. The ACLs in a default security descriptor for a key are inherited from its direct parent key.
这个lpSecurityAttributes 成员的结构体致命安全描述符给新的键。如果 lpSecurityAttributes 是NULL,这个键获得默认的安全描述符。这个ACLs在一个默认安全描述符给这个键是被继承的来自它直接的父键。
phkResult
A pointer to a variable that receives a handle to the opened or created key. If the key is not one of the predefined registry keys, call the RegCloseKey function after you have finished using the handle.
一个指针指向变量那是接收一个句柄去打开或者创建键。如果这个键不是一个预定义的注册表键,调用RegCloseKey函数后你要结束使用这个句柄。
lpdwDisposition
A pointer to a variable that receives one of the following disposition values.
一个指针指向变量那是接收一个下面的值。
Value Meaning
REG_CREATED_NEW_KEY
0x00000001L
The key did not exist and was created.
这个键不存在将被创建。
REG_OPENED_EXISTING_KEY
0x00000002L
The key existed and was simply opened without being changed.
这个键已经存在将简单的打开除非被改变。
If lpdwDisposition is NULL, no disposition information is returned.
如果lpdwDisposition是NULL, 没有配置信息被返回。
Return Value
If the function succeeds, the return value is ERROR_SUCCESS.
如果函数成功,返回值是ERROR_SUCCESS。
If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.
如果函数失败,返回值是非零错误代码定义在Winerror.h中。你可以用FormatMessage函数和FORMAT_MESSAGE_FROM_SYSTEM标志获得这个错误的一个普通的描述。
Remarks
The key that the RegCreateKeyEx function creates has no values. An application can use the RegSetValueEx function to set key values.
这个键是RegCreateKeyEx函数创建没有值。一个应用能RegSetValueEx函数去设置键值。
An application cannot create a key that is a direct child of HKEY_USERS or HKEY_LOCAL_MACHINE. An application can create subkeys in lower levels of the HKEY_USERS or HKEY_LOCAL_MACHINE trees.
一个应用不能创建一个键,HKEY_USERS 或HKEY_LOCAL_MACHINE 的一个直接孩子。一个应用能创建一个子键在HKEY_USERS 或HKEY_LOCAL_MACHINE的低层次树上。
If your service or application impersonates different users, do not use this function with HKEY_CURRENT_USER. Instead, call the RegOpenCurrentUser function.
如果你的服务或应用扮演不同的用户,不要用这个函数和HKEY_CURRENT_USER。代替调用RegOpenCurrentUser函数。
Note that operations that access certain registry keys are redirected. For more information, see Registry Virtualization and 32-bit and 64-bit Application Data in the Registry.
注意 这个操作访问某一个注册表键是被重定向的。更多信息,看Registry Virtualization and 32-bit 和 64-bit Application Data in the Registry。
Example Code
For an example, see Adding a Source to the Registry.
一个例子,看 Adding a Source to the Registry
Requirements
Client Requires Windows Vista, Windows XP, or Windows 2000 Professional.
Server Requires Windows Server 2008, Windows Server 2003, or Windows 2000 Server.
Header Declared in Winreg.h; include Windows.h.
Library Use Advapi32.lib.
DLL Requires Advapi32.dll.
Unicode Implemented as RegCreateKeyExW (Unicode) and RegCreateKeyExA (ANSI).
See Also
RegCloseKey
RegDeleteKey
Registry Functions
Registry Overview
RegOpenKeyEx
RegSaveKey
SECURITY_ATTRIBUTES
Send comments about this topic to Microsoft
Build date: 4/24/2008