The operation of the registry in the registry (original) in C #

xiaoxiao2021-03-06  61

The registry of the Windows operating system contains a lot of configuration information about the computer, open the registry. We can see that the registry is organized according to the tree structure similar to the directory, where the second level directory contains five predefined primary keys, respectively. : HKEY_CLASS_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_CURRENT_CONFIG. Let's explain the five classes of these five classes, HKEY_CLASSES_ROOT, the primary key contains the file extension and application information and the information of Window Shell and OLE to store registry. The subkey under this primary key determines how to display this class file and their icon in Windows, which is mapped from HKEY_LCCAL_MACHINE / SOFTWARE / CLASSES. HKEY_CURRENT_USER This primary key contains information such as user window information, desktop settings and other current users. The HKEY_LOCAL_MACHINE key key contains computer software and hardware installation and configuration information, which allows all users to use HKEY_USERS that primary key records the current user's setup information. When the user logs into the system, it will generate a login under the primary key. The same subkey, the subkey saves the current user's desktop settings, background bitmaps, shortcuts, fonts and other information. The general application does not directly access the transder key, but is accessed by the primary key HKEY_CURRENT_USER. HKEY_CURRENT_CONFIG This primary key holds configuration information of the computer current hardware, which can be changed according to the currently connected network type or the change in hardware drive software installation. C # also supports the editing of the registry, .NET Framework provides two classes in Microsoft.Win32 namespaces to operate registry: Registry and RegistryKey. Both classes are sealing and is not allowed to be inherited. Let's introduce these two classes separately. The Registry class provides 7 public static domains, representing 7 basic primary keys (two of which are not in the XP system, this is not introduced), respectively: Registry.classesRoot, Registry.Currentuser, Registry.localMachine, Registry , Registry.currentconfig. Which keys should be corresponding to what other keys, I will know it. A method for registry operation is provided in the RegistryKey class. It should be noted that the operational registry must meet system authority, otherwise an error will be thrown. Below we have a few ways to operate a few ways to operate the registry, the method of creating a subkey: public registryKey createSubkey; the parameter sunbkey indicates the name or path name of the sub-key to be created. Create successfully returns a subkey created, otherwise returns NULL.

The prototype of the open sub-key is: public registryKey OpenSubkey (String Name); PUBLIC RegistryKey OpenSubkey; Parameter Name Indicates whether the sub-key name or its path name to be opened, the parameter WRITABLE indicates whether the subkey is opened. Allow modifications, the sub-key that the first method open is read-only. Microsoft.Win32 class also provides us with another method to open registry on the remote computer, the prototype: public static registryKey OpenRemoteBaseKey (RegistryHive HKey, String Machinename); method of deleting sub-keys: public void deleteSubkey (String Subkey); This method is used to delete the specified primary key. If the subkey to be deleted, the primary key is deleted, and an exception is returned. If you want to completely remove the sub-key under the extreme directory, you can use the method deleteSubkeyTree, the prototype is as follows: public void deletesunkeyTree (String Subkey); The prototype of the key value is as follows: public object getValue; public object getValue (String Name, Object DefaultValue); Parameter Name Represents Name, return type is an Object type, return null if the specified key does not exist . If the value that the failure does not want to return is NULL, you can specify parameter defaultValue, specifying parameters, returns the value specified by the parameter without reading failure. The method of setting the key value is as follows: Public Object setValue; the method of deleting key values ​​is as follows: Public void deleteValue (String name); Wow time to eat, etc., continue to write an example. Yesterday because of eating a good meal to help friends find the paper to find a very play, I will write it, and I will write the example section today. This example is very simple to hide the running option under the Start menu, and the implementation method is also very simple. As long as the registry can also be implemented, here we use the program to implement, we passed in hkey_current_user /// window // CURRENTVERSION / / POLICIES / / Explorer Probate Norun Setting Up to 1 You can set it. We said that Windows desktop settings are placed in the HKEY_CURRENT_USER primary key.

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

New Post(0)