Well, apparently the registry seems to have lost some of its importance with the arrival of .NET, at least that's the
impression I seem to get. But luckily for us, Microsoft has given us two nice classes for doing just about anything we want to do
with the registry. The classes are
Microsoft.Win32.Registry. They have
both been put into the
Microsoft.Win32 namespace as you can see because the registry is totally Microsoft Win32
specific. Without too much fuss, let's get into business and try and do some of the stuff we normally do with the registry.
Reading the registry
RegistryKey rkey = Registry.LocalMachine;
listBox1.Items.Add("RegisteredOwner :- " +
listBox1.Items.Add("RegisteredOrganization :- " +
listBox1.Items.Add("ProductName :- " +
listBox1.Items.Add("CSDVersion :- " +
listBox1.Items.Add("SystemRoot :- " +
Writing to the registry
rkey = Registry.CurrentUser;
rkey1 = rkey.OpenSubKey("Software",true);
RegistryKey rkey2 = rkey1.CreateSubKey("Tweety");
If you open regedit, you'll see that the new key has been added and the values have indeed been written correctly.
Okay, we've read from and written into the registry. Now let's enumerate some values.
rkey1 = rkey.OpenSubKey("Software\\Microsoft\\" +
"Internet Account Manager\\Accounts\\00000001");
string s_arr = rkey1.GetValueNames();
foreach(String s in s_arr)
listBox1.Items.Add(s + " :- " + rkey1.GetValue(s));
Well, that's about it I guess. This was originally written as part of an internal tutorial. I didn't modify it too much except
for taking better screenshots.
Nish is a real nice guy who has been writing code since 1990 when he first got his hands on an 8088 with 640 KB RAM. Originally from sunny Trivandrum in India, he has been living in various places over the past few years and often thinks it’s time he settled down somewhere.
Nish has been a Microsoft Visual C++ MVP since October, 2002 - awfully nice of Microsoft, he thinks. He maintains an MVP tips and tricks web site - www.voidnish.com
where you can find a consolidated list of his articles, writings and ideas on VC++, MFC, .NET and C++/CLI. Oh, and you might want to check out his blog on C++/CLI, MFC, .NET and a lot of other stuff - blog.voidnish.com
Nish loves reading Science Fiction, P G Wodehouse and Agatha Christie, and also fancies himself to be a decent writer of sorts. He has authored a romantic comedy Summer Love and Some more Cricket
as well as a programming book – Extending MFC applications with the .NET Framework
Nish's latest book C++/CLI in Action
published by Manning Publications is now available for purchase. You can read more about the book on his blog.
Despite his wife's attempts to get him into cooking, his best effort so far has been a badly done omelette. Some day, he hopes to be a good cook, and to cook a tasty dinner for his wife.