Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Reading registry keys

Reading registry keys

Scheduled Pinned Locked Moved C#
csharpwindows-adminhelp
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rakeshs312
    wrote on last edited by
    #1

    Hi all, I have a prob ,how we can read the registry keys in c# and display or write it into a text file Please help Thanks in advance Rakesh

    A R A K 4 Replies Last reply
    0
    • R rakeshs312

      Hi all, I have a prob ,how we can read the registry keys in c# and display or write it into a text file Please help Thanks in advance Rakesh

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      Do a search on the internet - you will get tons of answers. See here[^] for the first link my search returned.

      The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it. My latest tip/trick

      1 Reply Last reply
      0
      • R rakeshs312

        Hi all, I have a prob ,how we can read the registry keys in c# and display or write it into a text file Please help Thanks in advance Rakesh

        R Offline
        R Offline
        RaviRanjanKr
        wrote on last edited by
        #3

        Navigate the Given Link to open Google Search Engine for tons of Answer for your question How to Read Registry Key[^] Hope it Will works for you. :-D

        1 Reply Last reply
        0
        • R rakeshs312

          Hi all, I have a prob ,how we can read the registry keys in c# and display or write it into a text file Please help Thanks in advance Rakesh

          A Offline
          A Offline
          Anil Kumar Arvapalli
          wrote on last edited by
          #4

          Include the required Header Files and then open ur required key RegistryKey Key = Registry.CurrentUser; Once Opening the key open ur sub key as needed.. RegistryKey SubKey = Key.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"); Read the values of sub keys into string (if it is a string else required data type) string str = SubKey.GetValue("AppData").ToString(); Then ur almost done write this str value into file stream, so that ur task is acheived.... If u like my answer.... rate it :)Thanks

          P 1 Reply Last reply
          0
          • A Anil Kumar Arvapalli

            Include the required Header Files and then open ur required key RegistryKey Key = Registry.CurrentUser; Once Opening the key open ur sub key as needed.. RegistryKey SubKey = Key.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"); Read the values of sub keys into string (if it is a string else required data type) string str = SubKey.GetValue("AppData").ToString(); Then ur almost done write this str value into file stream, so that ur task is acheived.... If u like my answer.... rate it :)Thanks

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Pardhu2 wrote:

            Include the required Header Files

            This is the C# forum.

            1 Reply Last reply
            0
            • R rakeshs312

              Hi all, I have a prob ,how we can read the registry keys in c# and display or write it into a text file Please help Thanks in advance Rakesh

              K Offline
              K Offline
              Kevin Marois
              wrote on last edited by
              #6

              Here ya go. Paste this code into a class and you're all set:

              using System;
              using System.Linq;
              using Microsoft.Win32;
              using System.Collections.Generic;

              namespace Marois.Common.RegistryProcedures
              {
              public static class RegistryProcedures
              {
              #region enum BaseKeys
              public enum BaseKey
              {
              HKEY_CLASSES_ROOT,
              HKEY_CURRENT_CONFIG,
              HKEY_CURRENT_USER,
              HKEY_DYN_DATA,
              HKEY_LOCAL_MACHINE,
              HKEY_PERFORMANCE_DATA
              }
              #endregion

                  #region Method CreateSubkey
                  public static void CreateSubkey(BaseKey BaseKey, string KeyToAdd)
                  {
                      CreateSubkey(BaseKey, "", KeyToAdd);
                  }
                  public static void CreateSubkey(BaseKey BaseKey, string SubKey, string KeyToAdd)
                  {
                      RegistryKey baseKey;
              
                      if (SubKey != "")
                          baseKey = \_GetRegistryBaseKey(BaseKey).OpenSubKey(SubKey, true);
                      else
                          baseKey = \_GetRegistryBaseKey(BaseKey);
              
              
                      if (baseKey == null && SubKey != "")
                      {
                          throw new Exception("Registry subkey not found");
                      }
                      else
                      {
                          baseKey.CreateSubKey(KeyToAdd);
                      }
                  }
                  #endregion
              
                  #region Method DeleteSubkey
                  public static void DeleteSubkey(BaseKey BaseKey, string SubKey)
                  {
                      RegistryKey baseKey = \_GetRegistryBaseKey(BaseKey);
                      baseKey.DeleteSubKey(SubKey);
                  }
                  #endregion
              
                  #region Method DeleteSubkeyTree
                  public static void DeleteSubKeyTree(BaseKey BaseKey, string sSubKey)
                  {
                      RegistryKey baseKey = \_GetRegistryBaseKey(BaseKey);
                      baseKey.DeleteSubKeyTree(sSubKey);
                  }
                  #endregion
              
                  #region Method DeleteSubkeyTreeValues
                  public static void DeleteSubkeyTreeValues(BaseKey BaseKey, string sSubKey)
                  {
                      List<string> nodeNames = GetSubKeyNodeNames(BaseKey, sSubKey);
              
                      if(nodeNames.Count > 0)
                      {
                          RegistryKey baseKey = \_GetRegistryBaseKey(BaseKey);
                          baseKey = baseKey.OpenSubKey(sSubKey, true);
              
                          foreach(string nodeName in nodeNames)
                          {
                              baseKey.DeleteValue(nodeName);                   
                          }
                      }
                  }
                  #endregion
              
                  #region Method DeleteValue
              
              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups