Click here to Skip to main content
16,021,041 members
Articles / Programming Languages / C#
Tip/Trick

Read Registry using C#

Rate me:
Please Sign up or sign in to vote.
3.33/5 (3 votes)
5 Dec 2011CPOL 40K   8   2
How to read a key from the Windows Registry.

This C# code snippet reads a key from the Windows Registry.


Warning: Do not play with the Registry. If you do not know what you are doing, you can cause any number of costly problems. Use this code at your own risk.

C#
using Microsoft.Win32;
...

RegistryKey masterKey = Registry.LocalMachine.CreateSubKey(
            "SOFTWARE\\Test\\Preferences");
if (masterKey == null)
{
    Console.WriteLine ("Null Masterkey!");
}
else
{
    Console.WriteLine ("MyKey = {0}", masterKey.GetValue ("MyKey"));
}
masterKey.Close();

License

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


Written By
Technical Lead Erls Corporation
India India
I am Dinesh kumar Choudhary by Name, a software Designer and Developer by Work, a Indian Hindu by Religion, Co-Founder of DSFoundation located at http://dsfoundation.wordpress.com by profession, a Loving husband and a Caring Father by Relation.

I have a blog Website at http://dennosecqtinstien.wordpress.com. DSFoundation is the Autonomous body to serve for the management of Local shops located at New Delhi, India. Now a days DSFoundation and its subsidiaries are managed by Erls Corporation, an Another initiative by me and my colleagues, in which i am the another CO-Founder of the Organization. Erls Corporation can be located at http:erlsindia.co.in

Comments and Discussions

 
GeneralReason for my vote of 1 Contains no explanation. Better alte... Pin
Ansgar Hellwig12-Dec-11 20:57
professionalAnsgar Hellwig12-Dec-11 20:57 
Reason for my vote of 1
Contains no explanation. Better alternatives available.
QuestionAccess is denied. Pin
kamiktk12313-Dec-11 5:17
kamiktk12313-Dec-11 5:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.