Application and examples of registry (on)

zhaozj2021-02-17  59

The application and examples of the registry (on) Text / Dong Yi likes the friends who like to program, I am afraid I don't know the VC's (Microsoft Visual C ). And I will use VC to build, modify and delete some of the cases of WINDOWS 9X registry, I hope that programming enthusiasts can get some inspiration. First let's take a look at our owner - registry. The registry is a hierarchical structure with a key and value. In the registry morder, keys can include sub-keys and values. We can make him a metaphor, the key is the directory, and the subkey and value can be seen as a file. This might may not science but very practical. The registry in Windows 98 is included in two files, they are user.dat and system.dat two files. System.dat includes standard system information, they are saved within the root key of HKEY_LOCAL_MACHINE, and the user is all. User.dat files include information specified by the user, such as user policies, desktop settings, and more. For us, it is convenient for WIN98 to prepare a small program regedit.exe for us. Execute him can see the tree structure of the registry. A basic program is required. You can use MFC to generate a single document or dialog program, if you think that you understand the C API enough to generate a main window, but I recommend to generate a dialog. In the MFC of the VC, there is also a function of the registry, but I will introduce you to the function of the registry in the API. The Win32 API provides a function of approximately 25 registry, which provides all functions for reading, writing, deleting, and opening registry and key values, and can reach backup, connection, and View the remote registry and so on. But first, you first need to consider why you have edited such programs when the operating system is edited. You will be asked why think about it? In Microsoft's operating system, we often have Windows NT, Windows 95, 98, 3.1, etc., now use NT and Win98, although they are 32-bit operating systems, but they don't support 98 in the function, this is to Note. The function is as follows:

Non-WIN98 function name function RegCloseKey RegConnectRegistry RegCreateKey RegCreateKeyEx RegDeleteKey RegDeleteVale RegEnumKey RegEnumKeyEx RegFlushKey RegGetKeySecurity is RegLoadKey RegNotifyChangeKeyValue is RegOpenKey RegOpenKeyEx RegQueryInfoKey RegQueryValue RegqueryValueEx RegReplaceKey RegRestoreKey is RegSaveKey RegSetKeySecurity is RegSetValue RegSetValueEx RegUnLoadKey Now I detailed description for each function we often use. The API experience and has developed for many years, so some functions have been repeated. For example, RegSetValue () and regSetValueex () are used to set the registry key value. The difference between the two is that the former is the default value for setting the registry key, only supports a string of the data type, but the latter not only inherits all the functions of the former but also operates a multi-value or type. General API contrast comparison new functions returns to the same name function of "EX" in the suffix, it is recommended to use advanced functions as much as possible in programming. The primary function is compatible. Similarly to other programs, the programming of the registry should also use the handle. Access the registry key value via a handle, when you open or create a key value, a handle of the key is returned, and the button and the creation key value are called, and the handle to function is required while analyzing and creation. Windows offers a predefined sensory root-level key for reserving handles. HKEY_CLASS_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USER. These are the handles corresponding to the root key of the registry and the same name. When accessing a root key, pass these universal handles. This doesn't turn on the root key, because they are always in the open state, you can use the handle of the default key to access. I have said so many preparations in front. Let's talk about the function. 1. RegcloseKey () prototype: regclosekey (HKEY HKEY) Explanation: Turn off the specified book key to release the handle. When the one or more keys or value operations are completed, it is necessary to turn off their keys to save the results. When a button is turned off, the handle becomes illegal to make it unused again. Release the handle for the system. Example: BOOL BRET = True;

IF (m_hKey == NULL)

Return (False);

Bret = (:: regclosekey = = error_success);

m_hKey = null;

Return (BRET);

2. RegcreateKeyex ()

Prototype: RegcreatKeyex (HKEY_CURRENT_SURE,

"Software // regApp // 1.0",

0,

"Regpp",

REG_OPTION_NON_VOLATILE, Key_All_Access,

NULL,

& HKeynew,

& dwdisposition)

Explanation: Open the specified key or subkey. If the key to open does not exist, this function will try to create it. Providing this function is backward compatible. All Win32 applications should use the function regreateKeyex (). When you create or open the registry, you need to specify access rights, and these access needs to be at first. The default permissions are Key_All_Access permissions. There is also key_create_link creates a character chain permissions, key_create_sub_key creation sub-key permissions, key_execute read key permissions, key_notify gets permissions for modifying key notifications, Key_Query_Value Query key values, key_set_value Sets the permissions of the data value. Note You cannot be built at the root first level, and only a predefined key can only be available at the root of the registry. example:

HKEY HOPENEDKEY;

DWORD DWDISPSITION;

DWORD DWLASTERROR;

Bool Bret = (: RegcreateKeyex (HKEY, LPSZSUBKEYEX (CHAR *) LPSZCLASS, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, & HopENEDKEY, & DWDISPOSITION = = Error_Success;

IF (BRET) :: regcloseKey (HopenedKey);

Dwlasterror = getLastError ();

Return (BRET);

3. RegdeleteKey ()

Prototype: RegdeleteKey (HKEY HKEY, LPCTSTR LPSUBKEY)

Explanation: RegdeleteKey () See the name can also know that he is used to delete a key value in the registry. There is a frequent creation and deletion of the registry, and the deleted parameters are only two, and HKEY represents the handle of the root key, and LPSubkey is the name of the key. Pay attention to 98 and NT differences when using this function. Before you delete a key, you must delete all sub-keys, you need to remove all sub-keys from the downward, and Windows98 does not have him so complicated, as long as the button and all its sub-keys can be removed.

example:

BOOL BRET;

DWORD DWLASTERROR;

Bret = (:: regdeletekey (hkey, lpszsubkey) == Error_Success;

Dwlasterror = getLastError ();

Let us know about his data type before talking about reading and writing. The regedit registry has three types of data types: string, binary value, DWORD value. In the case of Windows98, NT to support multiple data types. When the data exceeds 2 kB, the registry does not save him to the registry but directs the registry value to the data file. The value of Win32 is divided into the following REG_BINARY binary data, REG_DWORD32 bit double word, REG_NONE undefined value type, REG_SZ empty string, is the most universal format of saving strings.

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

New Post(0)