-3

I am writing a value into registry of my Windows.Now as per my requirement i have to read it without specifying the path name where it has been saved but i am not getting how to retrieve it. Here is the code to write ..

        Microsoft.Win32.RegistryKey exampleRegistryKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("ExampleTest");
        exampleRegistryKey.SetValue("Conn", "Connection Test");
        exampleRegistryKey.Close();

Please help me how to read this key. Thanks..

public static string PathName
{ 
get
{
    using (RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software\ExampleTest"))
     {
         return (string)registryKey.GetValue("Conn");
     }
}
}
Shivam Shlom
  • 33
  • 3
  • 9

1 Answers1

2

Use the following method to get a value of registry key by its name:

   public static string PathName
     { 
      get
         {
          RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Software\ExampleTest")
          string registryContent = (Registry.GetValue(registryKey.Name, "Con", "not exist")).ToString();
          return registryContent;  
         }
     }

The text "not exist" will be returned in case the Con value was not found in the registry.

InvertedAcceleration
  • 10,695
  • 9
  • 46
  • 71
user3165438
  • 2,631
  • 7
  • 34
  • 54