TechSapphire Monday, 2024-12-09, 4:54 PM
Site menu
Login form
News
Play Games
  • Deep Freeze
  • Ice Slide
  • Gyroball
  • Fat Fish
  • Bush Royal Rampage
  • Example in C#


    Imports Microsoft.VisualBasic

    Imports System

    Imports System.Security.Permissions

    Imports Microsoft.Win32

     

    Public Class RegKey

        Shared Sub Main()

     

            ' Create a subkey named Test9999 under HKEY_CURRENT_USER.

            Dim testkey As RegistryKey = _

                Registry.CurrentUser.CreateSubKey("Testkey")

     

            ' Create two subkeys under HKEY_CURRENT_USER\Testkey

            testkey.CreateSubKey("TestName").Close()

            Dim testSettings As RegistryKey = _

                testkey.CreateSubKey("TestSettings")

     

            ' Create data for the TestSettings subkey.

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

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

            testSettings.SetValue("ID", 1)

            testSettings.Close()

     

            ' Print the information from the Test9999 subkey.

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

                testkey.SubKeyCount.ToString())

            For Each subKeyName As String In testkey.GetSubKeyNames()

                Dim tempKey As RegistryKey = _

                    testkey.OpenSubKey(subKeyName)

                Console.WriteLine(vbCrLf & "There are {0} values for " & _

                    "{1}.", tempKey.ValueCount.ToString(), tempKey.Name)

                For Each valueName As String In tempKey.GetValueNames()

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

                        tempKey.GetValue(valueName).ToString())

                Next

            Next

     

            ' Delete the ID value.

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

            testSettings.DeleteValue("id")

     

            ' Verify the deletion.

            Console.WriteLine(CType(testSettings.GetValue( _

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

            testSettings.Close()

     

            ' Delete or close the new subkey.

            Console.Write(vbCrLf & "Delete newly created " & _

                "registry key? (Y/N) ")

            If Char.ToUpper(Convert.ToChar(Console.Read())) = "Y"C Then

                Registry.CurrentUser.DeleteSubKeyTree("Test9999")

                Console.WriteLine(vbCrLf & "Registry key {0} deleted.", _

                    testkey.Name)

            Else

                Console.WriteLine(vbCrLf & "Registry key {0} closed.", _

                    testkey.ToString())

                testkey.Close()

            End If

     

        End Sub

    End Class

     

    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