Click here to Skip to main content
15,064,915 members
Articles / Programming Languages / C#
Posted 5 Dec 2011

Tagged as


1 bookmarked

Writing Registry using C#

Rate me:
Please Sign up or sign in to vote.
1.43/5 (6 votes)
13 Dec 2011CPOL
Writing Registry using C#

This C# code snippet writes a key to 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.

using Microsoft.Win32;

RegistryKey masterKey = Registry.LocalMachine.CreateSubKey
if (masterKey == null)
   Console.WriteLine ("Null Masterkey!");
      masterKey.SetValue ("MyKey", "MyValue");
   catch (Exception ex)
      Console.WriteLine (ex.Message);


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


About the Author

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 by profession, a Loving husband and a Caring Father by Relation.

I have a blog Website at 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

Comments and Discussions

GeneralReason for my vote of 1 'Cos you can't vote zero ;-) Pin
Paul_Williams19-Dec-11 6:04
MemberPaul_Williams19-Dec-11 6:04 
GeneralReason for my vote of 1 why ? Pin
Selvin13-Dec-11 8:43
MemberSelvin13-Dec-11 8:43 
GeneralReason for my vote of 1 no explanation Pin
ToPr13-Dec-11 2:10
MemberToPr13-Dec-11 2:10 
GeneralThis is a repost of <a href=" Pin
Kim Togo12-Dec-11 22:18
professionalKim Togo12-Dec-11 22:18 
GeneralReason for my vote of 1 Contains no explanation. Plenty of b... Pin
Ansgar Hellwig12-Dec-11 20:58
professionalAnsgar Hellwig12-Dec-11 20:58 
GeneralReason for my vote of 1 Is this article adding any value ? Pin
YvesDaoust12-Dec-11 20:32
MemberYvesDaoust12-Dec-11 20:32 

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.