API---Registry programming

Source: Internet
Author: User

First come to know the key, item, Value bar:

There are five root keys on the left:

HKey_Classes_Root

HKey_Current_User

HKEY_Local_Machine

Hkey_user

Hkey_current_config

The root key expands to see Zijian : Like "software, Microsoft, Windows, CurrentVersion, etc. are all zijian.

And the last level is not the son Jian, but the item:Run.

Under the name bar are called key- value items .

The types under Type bar are called key-value items .

The keys under the data bar are called key value items.

RegCreateKeyEx () Introduction:

Function: Create or open a registry key.

Function prototype: LONG RegCreateKeyEx (
HKEY HKEY, the handle of the//key (RegCreateKey, the return value of RegCreateKey (), or a predefined value (that is, five root keys).
LPCTSTR Lpsubkey,//point to the name of the Zijian you want to create or open.
DWORD Reserved,//reserved value must be 0,
LPTSTR Lpclass,//points to a string that defines the type of the key. can be empty.
DWORD dwoptions,//properties of the newly created key.
Regsam samdesired,//Key access rights.
Lpsecurity_attributes lpsecurityattributes,//pointer to security_attributes structure.

Defines whether the returned handle can be inherited by a quilt process, or null to not inherit.
Phkey Phkresult,//pointer to the handle of the newly created or opened key, saves the returned handle.
Lpdword Lpdwdisposition//Indicates whether the key is created or opened
);

Parameter: dwoptions

Reg_option_non_volatile the newly created key is a non-ephemeral key (data information is saved in the file and data information is restored when the system restarts)
Reg_option_volatile the newly created key is a transient key (data information is stored in memory).
Reg_option_backup_restore is only supported in Winnt and can provide priority support.

Parameter: samdesired

Key_create_link allow generation of symbolic keys
Key_create_sub_key allow generation of sub-keys
Key_enumerate_sub_keys permission to generate an enumeration subkey
Key_execute permission to read operations
Key_notify Permit Change of notice
Key_query_value allow child keys to be queried
Key_all_access provides full access, which is a combination of the above values
Key_read is a combination of the following values:
Key_query_value, Key_enumerate_sub_keys, key_notify
Key_set_value allowed to set the value of the sub-key
Key_write is a combination of the following values:
Key_set_value, Key_create_sub_key

Parameter: lpdwdisposition

The Reg_create_new_key key was not previously present and is now created.
The Reg_opened_existing_key key was previously present and is now open.

Return value: Returns ERROR_SUCCESS if the function call succeeds. Otherwise, a nonzero error code is returned.

RegOpenKeyEx () Introduction:

Function: Open a Zijian that already exists.

Function prototypes: Lstatus RegOpenKeyEx (
HKEY HKEY,
LPCSTR Lpsubkey,
DWORD uloptions,//reserved value must be 0.
Regsam samdesired,
Phkey Phkresult
);

Parameters: Same as RegCreateKeyEx ().

Return value: Returns ERROR_SUCCESS if the function call succeeds. Otherwise, a nonzero error code is returned.

RegCloseKey () Introduction:
Function: Closes the registry.

Function prototype: LONG RegCloseKey (

HKEY the handle of the HKEY//release key. ); return value: Returns ERROR_SUCCESS if the function call succeeds. Otherwise, a nonzero error code is returned. Regdeletekey () Introduction:
Function: Delete registry key value. (You cannot delete Zijian) function prototypes that contain Zijian: Lstatus Regdeletekey (
HKEY HKEY,
LPCSTR Lpsubkey,
Regsam samdesired,
The DWORD Reserved//reserved value must be 0. ); return value: Returns ERROR_SUCCESS if the function call succeeds. Otherwise, a nonzero error code is returned. RegQueryValueEx () Introduction:
Function: Retrieves an open registry handle, specifying the type of registry key and setting the value. Function prototypes: Lstatus regqueryvalueexa (
HKEY HKEY,//Handle of open item, or specify a standard item name.
LPCSTR Lpvaluename,//To query the name string of the registry key value, the name of the registry key, ending with a null character.
Lpdword lpreserved,//reserved value must be 0.
Lpdword Lptype,//is used to mount a pointer variable that retrieves the data type.
Lpbyte lpdata,//is used to load a buffer of the specified value, which can be empty.
Lpdword lpcbdata//A variable to load the length of the lpdata buffer. Once returned, it is set to the number of bytes actually loaded into the buffer.
If lpdata is null, it is also null. ); parameter: Lptype is a pointer to a data type that has one of the following types of data:
REG_BINARY binary Data
REG_DWORD 32-bit integer
Reg_dword_little_endian data in Little-endian format, such as 0x12345678 (0X78 0X56 0x34 0X12) Save
Reg_dword_big_endian data in Big-endian format, such as 0x12345678 (0X12 0x34 0X56 0X78) Save
REG_EXPAND_SZ A string containing the non-extended environment variable
Reg_link a link to a Unicode type
REG_MULIT_SZ A string ending with two 0
Reg_none No type value
Reg_resource_list Device driver Resource list
REG_SZ A string ending in 0 is set to a Unicode or ANSI type string based on the character set type used by the function. Return value: Returns ERROR_SUCCESS if the function call succeeds. Otherwise, a nonzero error code is returned. RegSetValueEx () Introduction:Function: Sets the data and type of the specified value under the registry key. Function prototype: LONG RegSetValueEx (
HKEY HKEY,
LPCTSTR Lpvaluename,
The DWORD reserved,//reserved value must be 0.
DWORD dwtype,
CONST BYTE *lpdata,
DWORD cbdata
); parameters: Same as RegQueryValueEx (). Return value: Returns ERROR_SUCCESS if the function call succeeds. Otherwise, a nonzero error code is returned. Regdeletevalue () Introduction:Function: Deletes a value below the specified item. Function prototypes: Lstatus regdeletevalue (
HKEY HKEY,
LPCSTR lpvaluename//point to the name of the value you want to delete.
); return value: Returns ERROR_SUCCESS if the function call succeeds. Otherwise, a nonzero error code is returned. DEMO CODE:
#include <stdio.h>#include<Windows.h>intMainvoid) {long Long, LONG0; HKEY HKEY=NULL; CharBuffer[] ="www.baidu.com"; Long=RegOpenKeyEx (HKEY_LOCAL_MACHINE,"software\\microsoft\\internet Explorer\\main",        0, Key_all_access,&HKey); if(Long! =error_success) {printf ("Open error!\n"); System ("Pause"); Exit (0); } LONG0=RegSetValueEx (HKey,"Start Page",        0, REG_SZ, (CONST BYTE*) Buffer, strlen (buffer)); if(LONG0! =error_success) {printf ("Set Value error!\n"); System ("Pause"); Exit (0); } printf ("Modify succeed!\n"); System ("Pause"); return 0;}

API---Registry programming

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.