IT Community - Software Programming, Web Development and Technical Support

How to read and write System Registry Keys using C# (VS.Net 2005)

This is a discussion on How to read and write System Registry Keys using C# (VS.Net 2005) within the C# Programming forums, part of the Software Development category; How to read and write System Registry Keys using C# (VS.Net 2005)...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Software Development > C# Programming

Register FAQ Members List Calendar Mark Forums Read
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 07-20-2007, 04:26 AM
oxygen oxygen is offline
D-Web Architect
 
Join Date: Jun 2007
Posts: 633
oxygen is on a distinguished road
Default How to read and write System Registry Keys using C# (VS.Net 2005)

How to read and write System Registry Keys using C# (VS.Net 2005)
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-20-2007, 04:48 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: How to read and write System Registry Keys using C# (VS.Net 2005)

hi..... i give the explanation in detail.....below..

string strWindowsState;
string strPath;

Read from Registry:-


RegistryKey regKeyAppRoot = Registry.CurrentUser.CreateSubKey(strPath);
strWindowsState = (string)regKeyAppRoot.GetValue("WindowState");
if (strWindowsState != null && strWindowsState.CompareTo("Maximized") == 0)
WindowState = System.Windows.Forms.FormWindowState.Maximized;
else if (strWindowsState != null && strWindowsState.CompareTo("Minimized") == 0)
WindowState = System.Windows.Forms.FormWindowState.Minimized;
else
WindowState = FormWindowState.Normal;
label1.Text = strWindowsState;
label3.Text = "";
return;

Writing into Registry:-

strWindowsState = "";
RegistryKey regKeyAppRoot = Registry.CurrentUser.CreateSubKey(strPath);
if (WindowState == FormWindowState.Maximized)
strWindowsState = "Maximized";
else if(WindowState == FormWindowState.Maximized)
strWindowsState = "Minimized";
else
strWindowsState = "Normal";
regKeyAppRoot.SetValue("WindowState", strWindowsState);
label3.Text = strWindowsState;
label1.Text = "";
return;
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-31-2007, 11:41 PM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 1,061
S.Vinothkumar is on a distinguished road
Wink Re: How to read and write System Registry Keys using C# (VS.Net 2005)

Hi Friends….

Here is the code for read the registry value using C#.

First I’m creating registry key value and string value in local machine as follows,

myKey -> key value
myValue -> string name
myReturnValue -> string value

using Microsoft.Win32;

Code:
try
   {
     RegistryKey registry = Registry.LocalMachine.CreateSubKey("SOFTWARE\\myKey");
    if (registry != null)
      {
        MessageBox.Show(registry.GetValue("myValue"));
        registry.Close();
      }
   }
catch (Exception ex) 
{
 MessageBox.Show (ex.ToString()); 
}
Writing values in registry

Code:
using Microsoft.Win32;

try
   {
     RegistryKey registry = Registry.LocalMachine.CreateSubKey("SOFTWARE\\myKey");
    if (registry != null)
      {
        registry.SetValue("myValue", "myReturnValue");
        registry.Close();
      }
   }
catch (Exception ex) 
{
 MessageBox.Show (ex.ToString()); 
}

that's it...
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/c-programming/2302-how-read-write-system-registry-keys-using-c-vs-net-2005-a.html
Posted By For Type Date
Programming This thread Refback 07-20-2007 05:24 AM

Similar Threads
Thread Thread Starter Forum Replies Last Post
Attempted to read write protected memory Balasubramanian.S C# Programming 0 03-21-2008 09:47 PM
How to Read and write txt file using C# kingmaker C# Programming 2 08-25-2007 02:40 AM
How to convert read only mode to write only mode itbarota Testing Tools 1 08-21-2007 06:23 AM
Read and Write IPTC and EXIF metadata fro raw Images Balasubramanian.S C# Programming 4 08-03-2007 07:38 AM
How can I access the registry from C# code DOT NET 2005? Archer C# Programming 1 07-25-2007 03:20 AM


All times are GMT -7. The time now is 10:58 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0