.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

System Registry Operation

Posted By:Pankaj Mishra       Posted Date: August 12, 2008    Points: 25    Category: C#    URL: http://www.dotnetspark.com  
 

Hi,

Sometime we need to do Registry operation like Read from registry, Write to Registry, Delete from Registry and its very simple. .NET framework provide RegistryKey to do Registry operation.

Write to Registry

public static void WriteToRegistry()
{
string sKey = "myKey";// Key to write
object oValue = "MyVal"; //value to write
string sPath = "MyPath"; //registry Path
RegistryKey oRegistry = Registry.LocalMachine.CreateSubKey(sPath);
          if(oRegistry != null) 
          {
                    oRegistry.SetValue(sKey,oValue);
           }
     return;
}
 
Read from Registry


public static object ReadFromRegistry()
{
string sKey = "MyKey"; // Registry key
string sPath = "MyPath"; //registry Path
RegistryKey oRegistry = Registry.LocalMachine.OpenSubKey(sPath);
object result = null;
         if(oRegistry != null) 
         {
                 result = oRegistry.GetValue(sKey);
         }
      return(result);
}
 
Delete Registry Value

public static void DeleteFromRegistry()
{
string sKey = "MyKey"; // Registry key
string sPath = "MyPath"; //registry Path
RegistryKey oRegistry = Registry.LocalMachine.OpenSubKey(sPath);
      if(oRegistry  != null) 
      {
              oRegistry .DeleteValue(sKey);
      }

}

Cheers
Pankaj

 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend