TechSapphire Sunday, 2024-12-22, 2:46 PM
Site menu
Login form
News
Play Games
  • Deep Freeze
  • Ice Slide
  • Gyroball
  • Fat Fish
  • Bush Royal Rampage
  • Example in c#


    using System;

    using System.Security.Permissions;

    using Microsoft.Win32;

     

    class RegKey

    {

        static void Main()

        {

            // Create a subkey named Testkey under HKEY_CURRENT_USER.

            RegistryKey testkey =

                Registry.CurrentUser.CreateSubKey("Testkey");

            // Create two subkeys under HKEY_CURRENT_USER\Testkey. The

            // keys are disposed when execution exits the using statement.

            using(RegistryKey

                testName = testkey.CreateSubKey("TestName"),

                testSettings = testkey.CreateSubKey("TestSettings"))

            {

                // Create data for the TestSettings subkey.

                testSettings.SetValue("Language", "Hindi");

                testSettings.SetValue("Level", "Class");

                testSettings.SetValue("ID", 1);

            }

     

            // Print the information from the Testkey subkey.

            Console.WriteLine("There are {0} subkeys under {1}.",

                testkey.SubKeyCount.ToString(), testkey.Name);

            foreach(string subKeyName in testkey.GetSubKeyNames())

            {

                using(RegistryKey

                    tempKey = testkey.OpenSubKey(subKeyName))

                {

                    Console.WriteLine("\nThere are {0} values for {1}.",

                        tempKey.ValueCount.ToString(), tempKey.Name);

                    foreach(string valueName in tempKey.GetValueNames())

                    {

                        Console.WriteLine("{0,-8}: {1}", valueName,

                            tempKey.GetValue(valueName).ToString());

                    }

                }

            }

     

            using(RegistryKey

                testSettings = testkey.OpenSubKey("TestSettings", true))

            {

                // Delete the ID value.

                testSettings.DeleteValue("id");

     

                // Verify the deletion.

                Console.WriteLine((string)testSettings.GetValue(

                    "id", "ID not found."));

            }

     

            // Delete or close the new subkey.

            Console.Write("\nDelete newly created registry key? (Y/N) ");

            if(Char.ToUpper(Convert.ToChar(Console.Read())) == 'Y')

            {

                Registry.CurrentUser.DeleteSubKeyTree("Testkey");

                Console.WriteLine("\nRegistry key {0} deleted.",

                    testkey.Name);

            }

            else

            {

                Console.WriteLine("\nRegistry key {0} closed.",

                    testkey.ToString());

                key.Close();

            }

        }

    }


    Categories
    Programming [27]
    Tips for programming
    Security [2]
    Security Tips
    Google [1]
    Use google faster then ever you use
    Project [14]
    HTML [2]
    Electronics [0]
    Data Structure [0]
    Database [16]
    SQL SERVER
    SSRS [1]
    Sql Server Reporting Services
    Copyright MyCorp © 2024