RegCreateKeyEx!(50分)

  • 主题发起人 主题发起人 coolmyf
  • 开始时间 开始时间
C

coolmyf

Unregistered / Unconfirmed
GUEST, unregistred user!
请问哪位仁兄能够给我讲一下 RegCreateKeyEx的用法及参数的意义,最好有例子,不胜感激!
 
The RegCreateKeyEx function creates the specified key. If the key already <br>exists in the registry, the function opens it.<br><br>LONG RegCreateKeyEx(<br><br>&nbsp; &nbsp; HKEY hKey, // handle of an open key <br>&nbsp; &nbsp; LPCTSTR lpSubKey, // address of subkey name <br>&nbsp; &nbsp; DWORD Reserved, // reserved <br>&nbsp; &nbsp; LPTSTR lpClass, // address of class string <br>&nbsp; &nbsp; DWORD dwOptions, // special options flag <br>&nbsp; &nbsp; REGSAM samDesired, // desired security access <br>&nbsp; &nbsp; LPSECURITY_ATTRIBUTES lpSecurityAttributes, // address of key security structure <br>&nbsp; &nbsp; PHKEY phkResult, // address of buffer for opened handle &nbsp;<br>&nbsp; &nbsp; LPDWORD lpdwDisposition // address of disposition value buffer <br>&nbsp; &nbsp;); <br>&nbsp;<br><br>Parameters<br><br>hKey<br><br>Identifies a currently open key or any of the following predefined reserved <br>handle values: <br><br>HKEY_CLASSES_ROOT<br>HKEY_CURRENT_USER<br>HKEY_LOCAL_MACHINE<br>HKEY_USERS<br>The key opened or created by the RegCreateKeyEx function is a subkey of the key <br>identified by the hKey parameter. <br><br>lpSubKey<br><br>Points to a null-terminated string specifying the name of a subkey that this <br>function opens or creates. The subkey specified must be a subkey of the key <br>identified by the hKey parameter. This subkey must not begin with the backslash <br>character ('/'). This parameter cannot be NULL. <br><br>Reserved<br><br>Reserved; must be zero. <br><br>lpClass<br><br>Points to a null-terminated string that specifies the class (object type) of <br>this key. This parameter is ignored if the key already exists. <br><br>dwOptions<br><br>Specifies special options for the key. This parameter can be one of the <br>following values. <br><br>Value &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Meaning<br>REG_OPTION_NON_VOLATILE This key is not volatile; this is the default. <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; The information is stored in a file and is <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; preserved when the system is restarted. The <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RegSaveKey function saves keys that are not <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; volatile. <br>REG_OPTION_VOLATILE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Windows NT: This key is volatile; the information <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; is stored in memory and is not preserved when the <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; system is restarted. The RegSaveKey function does <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; not save volatile keys. This flag is ignored if <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; the key already exists. <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Windows 95: This value is ignored in Windows 95. <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If REG_OPTION_VOLATILE is specified, the <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; RegCreateKeyEx function creates a nonvolatile <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key and returns ERROR_SUCCESS.<br>REG_OPTION_BACKUP_RESTORE Windows NT: If this flag is set, the function <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ignores the samDesired parameter and attempts <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; to open the key with the access required to backup<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; or restore the key. If the calling thread has <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; the SE_BACKUP_NAME privilege enabled, the key is <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; opened with ACCESS_SYSTEM_SECURITY and KEY_READ <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; access. If the calling thread has the SE_RESTORE_NAME <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; privilege enabled, the key is opened with <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ACCESS_SYSTEM_SECURITY and KEY_WRITE access. If both <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; privileges are enabled, the key has the combined accesses <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for both privileges. <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Windows 95: This flag is ignored. Windows 95 does <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; not support security in its registry.<br>&nbsp;<br><br>samDesired<br><br>Specifies an access mask that specifies the desired security access for the new <br>key. This parameter can be a combination of the following values: <br><br>Value Meaning<br>KEY_ALL_ACCESS Combination of KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; KEY_NOTIFY, KEY_CREATE_SUB_KEY, KEY_CREATE_LINK, and <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; KEY_SET_VALUE access.<br>KEY_CREATE_LINK Permission to create a symbolic link.<br>KEY_CREATE_SUB_KEY Permission to create subkeys.<br>KEY_ENUMERATE_SUB_KEYS Permission to enumerate subkeys.<br>KEY_EXECUTE Permission for read access.<br>KEY_NOTIFY Permission for change notification.<br>KEY_QUERY_VALUE Permission to query subkey data.<br>KEY_READ &nbsp; &nbsp; &nbsp; Combination of KEY_QUERY_VALUE, KEY_ENUMERATE_SUB_KEYS, and <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;KEY_NOTIFY access.<br>KEY_SET_VALUE Permission to set subkey data.<br>KEY_WRITE Combination of KEY_SET_VALUE and KEY_CREATE_SUB_KEY access.<br>&nbsp;<br><br>lpSecurityAttributes<br><br>Pointer to a SECURITY_ATTRIBUTES structure that determines whether the returned <br>handle can be inherited by child processes. If lpSecurityAttributes is NULL, <br>the handle cannot be inherited. <br>Windows NT: The lpSecurityDescriptor member of the structure specifies a <br>security descriptor for the new key. If lpSecurityAttributes is NULL, the key <br>gets a default security descriptor.<br>Windows 95: The lpSecurityDescriptor member of the structure is ignored.<br><br>phkResult<br><br>Points to a variable that receives the handle of the opened or created key. <br><br>lpdwDisposition<br><br>Points to a variable that receives one of the following disposition values: <br><br>Value Meaning<br>REG_CREATED_NEW_KEY The key did not exist and was created.<br>REG_OPENED_EXISTING_KEY The key existed and was simply opened without <br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; being changed.<br>&nbsp;<br><br>Return Values<br><br>If the function succeeds, the return value is ERROR_SUCCESS.<br>If the function fails, the return value is a nonzero error code defined in <br>WINERROR.H. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM <br>flag to get a generic description of the error.<br><br>
 
tseug,首先谢谢你,不过这段我已经看过了,是帮助里的,就是看不太明白才向高手们请教的,还请大家帮忙,最好有个例子。<br>谢谢!谢谢!
 
// RegCreateKeyEx示例<br>procedure CreateKey(const RootKey : HKey; Key, ValueName, Value: string);<br>var<br>&nbsp; Handle: HKey;<br>&nbsp; Res,<br>&nbsp; Disposition: Integer;<br>begin<br>&nbsp; Res := RegCreateKeyEx(RootKey, PChar(Key), 0, '',<br>&nbsp; &nbsp; REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, nil, Handle, @Disposition);<br>&nbsp; if Res = 0 then begin<br>&nbsp; &nbsp; Res := RegSetValueEx(Handle, PChar(ValueName), 0,<br>&nbsp; &nbsp; &nbsp; REG_SZ, PChar(Value), Length(Value) + 1);<br>&nbsp; &nbsp; RegCloseKey(Handle)<br>&nbsp; end;<br>&nbsp; if Res &lt;&gt; 0 then<br>&nbsp; &nbsp; raise Exception.Create('Error updating registry')<br>end;<br><br>//调用函数<br>procedure TForm1.Button1Click(Sender: TObject);<br>begin<br>&nbsp; CreateKey(HKEY_LOCAL_MACHINE,'Software/mytext','myown','1');<br>end;
 
接受答案了.
 
后退
顶部