In this post i am going to explain that how to access the System Registry and how to read and write data to registry.
Step 1: First you need to import the below namespaces:
using Microsoft.Win32;
Step 2: Now create an object of Registry class:
RegistryKey regkey;
Step 3: Now access the registry and get the value of a key
regkey = Registry.CurrentUser.CreateSubKey(@”Software\Microsoft\FTP”);
if (regkey.GetValue(“Use PASV”) == null)
{
txtValue.Text = “No Value Specified”;
}
else
{
txtValue.Text = regkey.GetValue(“Use PASV”).ToString();
}
The above code gets the value of the “Use PASV” key from the
Registry\CurrentUser\Software\Microsoft\FTP path.
Step 4: Set the key value
regkey.SetValue(“Use PASV”, txtValue.Text);
December 19, 2008 at 7:27 am |
I tried above code but i got regkey value null.
Here is my code.
RegistryKey regkey;
regkey = Registry.CurrentUser.OpenSubKey(“HKEY_CURRENT_USER\\SOFTWARE\\MICROSOFT\\OFFICE\\12.0\\EXCEL\\SECURITY”, true);
December 19, 2008 at 7:40 am |
Hi Umesh,
You are using double slash in the registry path, use single slash instead.
e.g.
RegistryKey regkey;
regkey = Registry.CurrentUser.OpenSubKey(”HKEY_CURRENT_USER\SOFTWARE\MICROSOFT\OFFICE\12.0\EXCEL\SECURITY”, true);
I hope your code will work now.
January 17, 2009 at 1:58 am |
I want to get remote computer registry key
January 17, 2009 at 1:20 pm |
I found some links, hope these will help you:
http://www.andreavb.com/tip080007.html
http://www.andreavb.com/tip080003.html
http://www.codeproject.com/KB/system/networkplay.aspx
February 25, 2009 at 11:48 am |
This is reply to Umesh. As you told to use single slash instead double. But it gives error like “unrecognised escape sequence” in C#. Is it possible to type your scenario. Or is there any other way. Please suggest.
March 24, 2009 at 5:42 pm |
Hi,
Can you help me write a binary val to registry in c#. im new to the language and i searched through various articles in net but dint find any helpful tips:( If you could guide me thro if i’ll be happy!
Nice article..
I need to change the second set of values for a particular key, when i set a value using the SeValue() of Microsoft.Win32 namespace, Im able to write oly the first set of values and that too appears in hexadecimal format in the reg editor
Regards
Mala
March 25, 2009 at 6:24 am |
I got a few examples, hope these will help you out, visit:
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_23205582.html
http://www.xtremedotnettalk.com/showthread.php?t=86888
http://social.microsoft.com/Forums/en-US/netfxbcl/thread/96861ee1-d9f6-4bc9-b30a-8465232a5cd9