Registry API functions

Source: Internet
Author: User

for registry operations, the API provides about 25 functions.
he provides all functions for reading, writing, and deleting the registry, and enabling the Registry and key value.
In addition, He can back up the registry, connect to and view the remote registry.
the registry is very important to the entire system. You must first consider it before performing operations.
these functions are:
regclosekey regconnectregistry regcreatekey regcreatekeyex regdeletekey regdeletevale
regenumkey regflushkey reggetkeysecurity (this function is not applicable to 98) regloadkey
applicable) regopenkey regopenkeyex regqueryinfokey regqueryvalue
regqueryvalueex regreplacekey regrestorekey (98 not applicable) regsavekey regsetkeysecurity (98 not applicable) regsetvalue regsetvalueex regunloadkey

We will introduce several frequently used functions.
1. regclose ()
Prototype: Long regclosekey (
Hkey // release the opened registry handle
);
Returned value: If the return value is unsuccessful, non-0 is returned. If the return value is successful, error_success is returned.
Description: closes the specified Primary table key and releases the handle. After one or more key or value operations are completed, you need to disable the key to save the operation results. When a key is closed, the handle becomes invalid so that it cannot be used again. Release the handle for system reuse.
Example
Bool Bret = true;
If (m_hkey = NULL)
Return (false );
Bret = (: regclosekey (m_hkey) = error_success );
M_hkey = NULL;
Return (BRET );

2. regcreatekeyex () and regcreatekey ()
Prototype: Long regcreatekeyex (
Hkey, // primary key name
Lptstr lpsubkey, // sub-key name or path
DWORD reserved, // reserved, 0
Lptstr lpclass, // I don't understand it. It's almost the same if I set it to null.
DWORD dwoptions,
/* Some options for the key you created can be these values: reg_option_non_volatile, reg_option_volatile, and reg_option_backup_restore. The first one is the default one. Generally, you can use the first one. */
Regsam samdesired, // set your access permission for the key you created
Lpsecurity_attributes lpsecurityattributes,
// Not quite clear
Phkey phkresult, // point to the handle you created
Lpdword lpdwdisposition // used to check whether an existing key is opened or a new key is created.
);
Regcreatekey () functions are much simpler. Please read them yourself.
Returned value: If the return value is unsuccessful, the return value is not 0. If the return value is successful, the return value is error_success.
Explanation: Open the specified key or sub-key. If the key to be opened does not exist, this function will try to create it. When you create or open a registry key, you need to specify the access permissions, and these access permissions need to level 1. The default permission is key_all_access. Key_create_link is also used to create character chains, key_create_sub_key is used to create subkeys, key_execute is used to read keys, key_policy is used to modify key notifications, key_query_value is used to query key values, and key_set_value is used to configure. Note that keys cannot be created at the root level. Only predefined keys are available at the root level of the Registry. For more information, see the online manual.
Example:
Hkey m_hkey;
DWORD dwdisposition;
Long ret0 = (: regcreatekeyex
(HKEY_CURRENT_USER, "regd \", 0, null,
Reg_option_non_volatile, key_all_access, null, & m_hkey, & dwdisposition ));
If (ret0! = Error_success) // If the hkey cannot be opened, terminate Program Execution
{
MessageBox ("error: Unable to open the relevant hkey! ");
Return;
}
If (dwdisposition = reg_opened_existing_key)
MessageBox ("an existing key is enabled ");
Else
{
If (dwdisposition = reg_created_new_key)
MessageBox ("Create a new key ");
}
Regclosekey (m_hkey );

 

3. regopenkey () and regopenkeyex ()
Prototype: Long regopenkeyex (
Hkey, // name of the primary key to be opened
Lptstr lpsubkey, // sub-key or path
DWORD uloptions, // reserved, 0
Regsam samdesired, // operation permission flag
Phkey phkresult // The handle pointing to your open key
);
Returned value: If the return value is unsuccessful, the return value is not 0. If the return value is successful, the return value is error_success.
Explanation: This function is used to open a specified key or subkey. If it does not exist, it is not created. The others are basically the same as regcreatekeyex () and regcreatekey.

4. regdeletekey ()
Prototype: Long regdeletekey (
Hkey, // handle of the opened key
Lptstr lpsubkey // The Sub-key or path to be deleted. If this parameter is set to "", the key itself will be deleted.
);
Returned value: If the return value is unsuccessful, non-0 is returned. If the return value is successful, error_success is returned.
This function is used to delete a key value in the registry. Note the differences between 98 and NT when using this function. Before deleting a key in NT, you must delete all subkeys. Instead, you must recursively Delete All subkeys from the bottom up. Windows 98 is not as complex as Windows 98, you only need to delete the key and all its subkeys.

5. regqueryvalue () and regqueryvalueex ()
Prototype: Long regqueryvalueex (
Hkey, // handle of the opened key
Lptstr lpvaluename, // name of the value to be queried, for example, "" is the default value under the query key
Lpdword lpreserved, // reserved, 0
Lpdword lptype, // query type
Lpbyte lpdata, // data storage address
Lpdword lpcbdata // Data Length + 1
);
Returned value: If the return value is unsuccessful, non-0 is returned. If the return value is successful, error_success is returned.
Explanation: reads the value of a specific name under a subkey.
Example
Cstring m_strq; // used to store the queried string value
DWORD m_dwcount; // record String Length + 1 (including null characters)
: Regqueryvalueex (m_hkey, "", 0, null, null, & m_dwcount); // first query the byte Space
Ret1 = (: regqueryvalueex
(M_hkey, "", 0, null, (unsigned char *) m_strq.getbuffer (m_dwcount), & m_kk ));
M_strq.releasebuffer ();
MessageBox (m_strq );

6. regsetvalue () and regsetvalueex ()
Prototype: Long regsetvalueex (
Hkey, // handle of the opened key
Lpctstr lpvaluename, // name of the value to be queried, for example, "" is the default value under the query key
DWORD reserved, // Reserved
DWORD dwtype, // variable type
Const byte * lpdata, // variable data address
DWORD cbdata // Variable Length
);
Returned value: If the return value is unsuccessful, non-0 is returned. If the return value is successful, error_success is returned.
Description: sets the value of a specific name under a subkey.

7. regenumvalue ()
Prototype: Long regenumvalue (
Hkey, // handle of the opened key to be queried
DWORD dwindex, // read the index number of the name
Lptstr lpvaluename, // return the read name
Lpdword lpcbvaluename, // returns the length of the read name, excluding CHR (0)
Lpdword lpreserved, // reserved, 0
Lpdword lptype, // return the Data Type Read
Lpbyte lpdata, // return the read data
Lpdword lpcbdata // return the length of the read data
);
Returned value: If the return value is unsuccessful, non-0 is returned. If the return value is successful, error_success is returned.
Explanation: lists the values of all names of a key. You can traverse the names and data of the entire key by changing the index.

8. regdeletevalue ()
Prototype: Long regdeletevalue (
Hkey, // handle of the key to be deleted
Lpctstr lpvaluename // name to be deleted
);
Returned value: If the return value is unsuccessful, non-0 is returned. If the return value is successful, error_success is returned.
Explanation: deletes a name of a key.

9. regenumkey () and regenumkeyex ()
Prototype: Long regenumkeyex (
Hkey, // handle of the key to be listed
DWORD dwindex, // Index
Lptstr lpname, // subkey name
Lpdword lpcbname, // length of the sub-key name
Lpdword

Lpreserved, // Reserved
Lptstr lpclass, // address of buffer for class string
Lpdword lpcbclass, // address for size of Class Buffer
Pfiletime lpftlastwritetime
// Address for time key last written
);
Returned value: If the return value is unsuccessful, non-0 is returned. If the return value is successful, error_success is returned.
Returns the details of the registry key and its subkeys.

10. regqueryinfokey ()
Prototype: Long regqueryinfokey (
Hkey, // handle of the opened key
Lptstr lpclass, // type name, used only for NT. If this parameter is not used, null is input.
Lpdword lpcbclass, // The length of the type name
Lpdword lpreserved, // Reserved
Lpdword lpcsubkeys, // returns the number of subkeys
Lpdword lpcbmaxsubkeylen, // returns the longest child Key Length
Lpdword lpcbmaxclasslen, // returns the longest class Length
Lpdword lpcvalues, // number of returned values
Lpdword lpcbmaxvaluenamelen, // return the length of the longest value item name
Lpdword lpcbmaxvaluelen, // returns the length of the longest Value
Lpdword lpcbsecuritydescriptor, // returns the Security description, applicable only to NT
Pfiletime lpftlastwritetime // The time when the return key was last written, only applicable to NT
);
Returned value: If the return value is unsuccessful, non-0 is returned. If the return value is successful, error_success is returned.
Explanation: The registry key information is returned, including the class name, the number of subkeys, the longest key name, the number of values, the longest value data, the length of the security descriptor, And the last write time.

 

11. regloadkey ()
Prototype: Long regloadkey (
Hkey, // Open Handle
Lptstr lpsubkey, // sub-Key Path
Lptstr lpfile // the file to write the Registry Information
);
Returned value: If the return value is unsuccessful, non-0 is returned. If the return value is successful, error_success is returned.
Explanation: restores the subkey information of the registry key from the specified file to the Registry.

12. regreplacekey ()
Prototype: Long regreplacekey (
Hkey, // handle to open key
Lptstr lpsubkey, // address of name of subkey
Lptstr lpnewfile, // generate a new backup file before replacement
Lpctstr lpoldfile // the file on which the registry needs to be overwritten
);
Returned value: If the return value is unsuccessful, non-0 is returned. If the return value is successful, error_success is returned.
Explanation: restores the subkey information of the registry key from the specified file to the Registry, replaces the original value, and generates a new backup file.

13. regsavekey ()
Long regsavekey (
Hkey, // the handle to save
Lptstr lpfile, // save the file of the sub-Key
Lpsecurity_attributes lpsecurityattributes // do not understand
);
Returned value: If the return value is unsuccessful, non-0 is returned. If the return value is successful, error_success is returned.
Explanation: Save the key and Its subkey information to the specified file.

14. regconnectregistry ()
Prototype: Long regconnectregistry (
Lptstr lpmachinename, // remote computer name
Hkey, // pre-registered handle
Phkey phkresult // handle on the remote computer
);
Returned value: If the return value is unsuccessful, non-0 is returned. If the return value is successful, error_success is returned.
Explanation: connect to the registry of the remote system.

15. regpolicychangekeyvalue ()
A notification is provided when the specified registry object is modified.

16. regunloadkey ()
Long regunloadkey (
Hkey, // handle to open key
Lptstr lpsubkey // address of name of subkey to unload
);
Returned value: If the return value is unsuccessful, non-0 is returned. If the return value is successful, error_success is returned.
Delete the registry key and all its subkeys.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.