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)...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| 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; |
| |||
| 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());
} 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! |
![]() |
| Thread Tools | |
| Display Modes | |
| |
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 |