Acessing the Windows Registry using C##

Here is a quick example on how to access the registry in .NET. This example just loops thru each entry in the selected folder in the registry and prints the gathered information to the console.

using System;
using Microsoft.Win32;

namespace Acessing_Registry
{
    class AccessingRegistry
    {
        [STAThread]
        static void Main(string[] args)
        {
            //create a object that would reference to the parent registry type folder
            RegistryKey regKey = Registry.LocalMachine;
            //assign a path in the registry to read
            regKey = regKey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0");
            //loop thru each entry in the registry
            foreach(string keyName in regKey.GetValueNames())
            {
                //read and display that keyName's value
                Console.WriteLine(keyName + ":" + regKey.GetValue(keyName));
            }
            //display the output to the screen
            Console.ReadLine();
        }
    }
}

The important thing to note on this example is that we first declare the location on where to read the key and reference that key by its name to get the underlying value/s.

Friday, August 12, 2005 8:55:32 AM (GMT Daylight Time, UTC+01:00) #    Comments [0]  |  Tracked by:
"spamfreeforum" (online) [Trackback]
"coco chanel handbag" (online) [Trackback]
"davidoff cigars" (online) [Trackback]
"thomas myspace editor" (online) [Trackback]
"baked red snapper" (online) [Trackback]
"koa camp grounds" (online) [Trackback]

 

Comments are closed.
All content © 2010, Keith Rull
On this page
This site
Calendar
<July 2010>
SunMonTueWedThuFriSat
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
Archives
Sitemap
Blogroll OPML
Disclaimer

Powered by: newtelligence dasBlog 2.3.9074.18820

The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts


Pick a theme: