C#. NET Operation Registry RegistryKey

Source: Internet
Author: User
Tags delete key
Look at the help of RegistryKey to know that this thing is not complicated, such as:

1, add the key to add value

String appName = "Poweroffontime";//Gets the assembly that executes the method and gets the file path to the assembly (the directory where the assembly is located by the file path) string Thisexecutablepath = System.Reflection.Assembly.GetExecutingAssembly (). This path in the Location;//software\\microsoft\\windows\\currentversion\\run registry is the boot-initiated path Microsoft.Win32.RegistryKey Rkey =    Microsoft.Win32.Registry.LocalMachine.CreateSubKey    ("Software\\microsoft\\windows\\currentversion\\run"); Rkey.setvalue (AppName, Thisexecutablepath); Rkey.close ();

The effect is as follows:


2, read the key value


Microsoft.Win32.RegistryKey Rkey =                   Microsoft.Win32.Registry.LocalMachine.CreateSubKey                   ("software\\ Microsoft\\windows\\currentversion\\run "); string  Key = Rkey.getvalue (" Poweroffontime "). ToString ();

The effect is as follows:



3. Create a new file in the registry and add the key value under the folder


String appName = "Poweroffontime";//Gets the assembly that executes the method and gets the file path to the assembly (the directory where the assembly is located by the file path) string Thisexecutablepath = System.Reflection.Assembly.GetExecutingAssembly (). Location; RegistryKey src = Registry.LocalMachine.OpenSubKey ("Software", true). OpenSubKey ("Microsoft", true). OpenSubKey ("Windows", true). OpenSubKey ("CurrentVersion", true). OpenSubKey ("Run", true);//Writes a registry key (that is, a folder) RegistryKey red = src. CreateSubKey ("Poweroffontime");//write the value red in this folder. SetValue (AppName, Thisexecutablepath);

The effect is as follows:



4. Delete key


RegistryKey src = Registry.LocalMachine.OpenSubKey ("Software", true). OpenSubKey ("Microsoft", true). OpenSubKey ("Windows", true). OpenSubKey ("CurrentVersion", true). OpenSubKey ("Run", true); Src. DeleteSubKey ("Poweroffontime");

The effect is as follows:



Small bet

Modify the registry, especially the boot automatically start the registry the biggest advantage is that when you write a small program, you can automatically execute every day, such as: you want to write a small program to automatically shut down the computer ....

The above is C #. NET operation Registry RegistryKey content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!

  • Related Article

    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.