Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

Access the Registry

Scenario/Problem:You need to read and/or write settings in the registry.
Solution:Use the Registry and RegistryKey classes located in the Microsoft.Win32 namespace:
//read from HKLM
using (RegistryKey hklm = Registry.LocalMachine)
using (RegistryKey keyRun =
     hklm.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run"))
{
    foreach (string valueName in keyRun.GetValueNames())
    {
        Console.WriteLine("Name: {0}\tValue: {1}",
                 valueName, keyRun.GetValue(valueName));
    }
}

Note

Registry keys are represented by handles, which are system resources that must be disposed of, hence the using statements.



  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial