Click here to Skip to main content
12,822,050 members (44,849 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


1 bookmarked
Posted 8 Dec 2011

Read Registry using C#

, 8 Dec 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
You can try the function below to read values from the Registry:myRegistry.Read("MY_KEY");where: input: the key name (string)output: the value of the key (string)using System;using Microsoft.Win32; public string Read(string KeyName){ // Opening the registry key ...

You can try the function below to read values from the Registry:



  • input: the key name (string)

  • output: the value of the key (string)

using System;
using Microsoft.Win32;  
public string Read(string KeyName)
    // Opening the registry key
      RegistryKey rk = baseRegistryKey ;
    // Open a subKey as read-only

    RegistryKey sk1 = rk.OpenSubKey(subKey);
    // If the RegistrySubKey doesn't exist -> (null)

    if ( sk1 == null )
        return null;
       // If the RegistryKey exists I get its value or null is returned.        
         return (string)sk1.GetValue(KeyName.ToUpper());
        catch (Exception e)
            ShowErrorMessage(e, "Reading registry " + KeyName.ToUpper());
            return null;

Note: if MY_KEY doesn't exist, the Read function will return null.

Find some more functions to perform write, delete a single key, delete a subkey, and many more from this link: Read, write and delete from registry with C#[^]. In addition, have a look there-Reading and Writing to the Registry][^] to get detailed lessons on how to read and write to the Registry.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
India India
Microsoft Student Partner | MCTS | CP MVP | Crazy Learner

An Indian, who loves his country, believes in freedom, He is an enthusiast Techie and crazy learner. He is passionate about Technologies. He holds Master in Computer Application and Bachelor degree of CS in Information Technology.

He always excited and keen Interested in learning and sharing knowledge. He loves to learn new things, listen music, taking arts and Playing Games..

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 8 Dec 2011
Article Copyright 2011 by RaviRanjanKr
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid