Registry programming literacy (1)

xiaoxiao2021-03-06  46

Foreword

I saw a book in the registry today, I feel that it is not bad. I also wrote a registry programming. Oh, I will put it on my understanding now, please share it with you :)

What is the registration table I don't have to say it, anyway, everyone knows. do not know? In fact, the registration form is ... that is ... that is, it's so, I can't clear it. One thing can be sure, can create a very cattle effect by modifying the registry, such as automatic operation, hiding the drive, there is a lot of pull, countless. Another example is that there is a multi-software function now, in fact, it is all modified to change the registration. Oh, I said so much nonsense, I am sorry, Well, I am starting now.

The operation registry mainly wants to rely on the API, I am counting, 1, 2, 3, ... a lot, write some commonly used. I don't know why, there are so many registry API, but MS did not package them into a class, very unhappy. Ok, first introduce an important variable type of an operational registry: HKEY, look at this type with h, you know that it is a handle. What is a handle, I don't understand, but it seems that every Win32 programming is used to use the handle, and the handle according to the defined say is a void *, but the pointer said in peace is not the same. Anyway, HKEY is a Handle to a registry key, which is written on MSDN. Translation should be a handle of a registry key, I don't know if it is right, oh, I blame me I didn't learn well, let everyone laugh. One handle is used in the operational registry. Ok, I said so much to introduce a few API.

One. RegcreateKeyex

Well, let's take a look at RegcreateKeyex, let's see the literal meaning of this function knows that it is created a key. If this button already exists, it is quite open. Yes, there is still a concept, what is the key. In fact, I can't say a word, I can't say a bit like a folder, I don't understand ... I don't say it. The statement of this function is like this:

Long RegcreateKeyex (

HKEY HKEY,

LPCTSTR LPSUBKEY,

DWORD reserved,

LPTSTR LPCLASS,

DWORD DWOPTIONS,

Regsam samdesired,

LPSecurity_attributes lpsecurityattributes,

Phkey phkresult,

LPDWORD LPDWDISPSITION

);

I am a number, 1, 2, 3 ... I rely, a total of nine parameters, exhausted me. How is so many parameters? take a look.

HKEY: This is a handle of a key that has been opened, it seems to establish a subkey in a key that has already opened. It is like the same word to build a word directory in an existing directory. Yes, if you start there is a handle that has already opened the key, what should I do? If there is a way, HKEY can also be the following value:

HKEY_CLASSES_ROOT

HKEY_CURRENT_CONFIG

HKEY_CURRENT_USER

HKEY_LOCAL_MACHINE

HKEY_USERS

HKEY_PERFORMANCE_DATA (WinNT && Win2k)

HKEY_DYN_DATA (Win98 && Win95 && WinMe)

In fact, in general, the value of HKEY is these kinds. Specifically, open the registry editor, see it :) Say more than your computer with a, c, d .. a few disks, the registry also has a few such things.

LPSUBKEY: A string, don't say what it means? That is to say which position you want to put your registry key. There are two points to pay attention, first LPSUBKEY can't be NULL, and it is (/), to write (//). Reserved: Nothing, must be 0.

LPClass: It's a string, it is said to specify the type of key you want to build, and I don't know how to use it for NULL.

DwOptions: Some options for the keys you created. Can be these values: REG_OPTION_NON_VOLATILE,

REG_OPTION_VOLATILE,

REG_OPTION_BACKUP_RESTORE

The first is the default. Generally, you can use the first one.

Samdesired: It seems that you have access to this new key, joke, I am built myself, I am now setting to key_all_access, that is, how about how to do.

LPSecurityAttributes: It is very troublesome, it's too lazy to say anyway, it is not very important, or set it to null.

PhkResult: This is a very important parameter. After you build a button, the handle of this button is placed here, and it will be rely on it later. Note that it is a pointer to HKEY.

LPDWDisPosition: Another pointer, after calling this function, can detect it to detect an existing key (REG_OPENED_EXISTING_KEY) or establish a key (REG_CREATED_NEW_KEY).

There is also a problem, it is the problem of return value. If you return Error_Success, it is 0, congratulations, succeed. Last example:

#include

void main ()

{

DWORD DWRES;

HKEY HK;

RegcreateKeyex (HKEY_LOCAL_MACHINE,

"Software // Carrier Studio // Hello",

0,

NULL,

REG_OPTION_NON_VOLATILE,

Key_all_access,

NULL,

& hk,

& dwres

);

IF (dwres == rag_created_new_key)

{

Printf ("New Key !! / N");

}

}

转载请注明原文地址:https://www.9cbs.com/read-110270.html

New Post(0)