In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces .NET 5 how to operate the registry, the article introduces in great detail, has a certain reference value, interested friends must read it!
About the registry
The registry is a storage device that provides information about applications, users, and default system settings. For example, an application can use the registry to store information that needs to be retained after the application is closed and access the same information when the application is reloaded. For example, you can store color preferences, screen position, or window size. You can control this data for each user by storing information in different locations in the registry.
Description
To manipulate the registry in C #, we need to use the Registry class to provide a RegistryKey object that represents the root key in the Windows registry and a static method to access the key / value pair.
Namespace: Microsoft.Win32
Assemblies: Microsoft.Win32.Registry.dll
Public static class Registry
In .net Framework x. In the application, we only need to add Microsoft.Win32.
Using Microsoft.Win32;namespace ConsoleApp3 {class Program {static void Main (string [] args) {/ / created a subkey TestKey RegistryKey testKey = Registry.CurrentUser.CreateSubKey ("TestKey") under storing information about user preferences;}
In .NET 5, this feature is no longer available by default and needs to be installed separately in NuGet, as shown below:
The scope of use of the Registry class is as follows:
RegistryKey
RegistryKey represents the key-level node in the Windows registry. A variety of public RegistryKey are available in the Registry static class.
Field
CurrentUser stores information about user preferences.
LocalMachine stores configuration information for the local computer.
ClassesRoot stores information about types (and classes) and their properties.
Users stores information about the default user configuration.
PerformanceData stores performance information for software components.
CurrentConfig stores hardware information that is not user-specific.
DynData stores dynamic data.
Method
The Registry class also contains methods that static GetValue SetValue uses to set and retrieve values in registry keys. These methods turn the registry key on and off every time they are used, so RegistryKey when you access a large number of values, they do not execute and similar methods in the class.
Create / read / delete registry key using Microsoft.Win32;namespace ConsoleApp2 {class Program {static void Main (string [] args) {/ / create a TestKey registry key value RegistryKey testKey = Registry.CurrentUser.CreateSubKey ("TestKey"); / / create subkey var nameKey = testKey.CreateSubKey ("Name") / / create key values nameKey.SetValue ("Id", 123); nameKey.SetValue ("Language", "China"); / / read the values in the subitems var readKey = testKey.OpenSubKey ("Name"); / / idString=123 var idString= readKey.GetValue ("Id") .ToString () / / Delete subkey testKey.DeleteSubKey ("Name");} effect
Open the Windows Registry Editor and you will find that the registry key created in the previous step will be in the specified top-level node
The above is all the contents of the article "how to operate the registry in .NET 5". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 216
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.