Click here to Skip to main content
Click here to Skip to main content

Tagged as

Writing Registry using C#

, 13 Dec 2011
Rate this:
Please Sign up or sign in to vote.
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
   ("SOFTWARE\\Test\\Preferences");
if (masterKey == null)
{
   Console.WriteLine ("Null Masterkey!");
}
else
{
   try
   {
      masterKey.SetValue ("MyKey", "MyValue");
   }
   catch (Exception ex)
   {
      Console.WriteLine (ex.Message);
   }
   finally
   { 
      masterKey.Close();
   }
}

License

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

Share

About the Author

Denno.Secqtinstien
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
Follow on   Twitter

Comments and Discussions

 
GeneralReason for my vote of 1 'Cos you can't vote zero ;-) PingroupPaul @ The Computer Station19-Dec-11 6:04 
GeneralReason for my vote of 1 why ? PinmemberSelvin13-Dec-11 8:43 
GeneralReason for my vote of 1 no explanation PinmemberToPr13-Dec-11 2:10 
GeneralThis is a repost of <a href="http://www.codeproject.com/Tips... PinmemberKim Togo12-Dec-11 22:18 
This is a repost of
http://www.codeproject.com/Tips/294991/Read-Registry-using-Csharp
 
Please delete this tips and stick to the other tip Smile | :)
GeneralReason for my vote of 1 Contains no explanation. Plenty of b... PinmemberAnsgar Hellwig12-Dec-11 20:58 
GeneralReason for my vote of 1 Is this article adding any value ? PinmemberYvesDaoust12-Dec-11 20:32 

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 13 Dec 2011
Article Copyright 2011 by Denno.Secqtinstien
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid