65.9K
CodeProject is changing. Read more.
Home

Read Registry using C#

starIconstarIconstarIconstarIconstarIcon

5.00/5 (2 votes)

Dec 7, 2011

CPOL
viewsIcon

5900

This is the code that I use:For lookup:RegistryKey rkn = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Test");dwResult = rkn.GetValue("Preferences");For update:RegistryKey rkn = Registry.LocalMachine.CreateSubKey(szKeyPath); dwResult = rkn.ValueCount;rkn.SetValue(szKey,...

This is the code that I use:

For lookup:

RegistryKey rkn  = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Test");
dwResult = rkn.GetValue("Preferences");

For update:

RegistryKey rkn  = Registry.LocalMachine.CreateSubKey(szKeyPath);             
dwResult = rkn.ValueCount;
rkn.SetValue(szKey, szValue);

For insert:

RegistryKey rkn = Registry.LocalMachine.CreateSubKey("Software\\Test");
rkn.SetValue("Preferences1", "xxxx");

I hope that helps.