Blog of a Filipino Developer about C#, VB.NET, ASP.NET, Java, PHP, SQL Server, MySql and Oracle RSS 2.0
 Friday, August 12, 2005

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 7:55:32 AM (GMT Standard Time, UTC+00:00)  #    Comments [0] -
.NET
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]
Archive
<August 2005>
SunMonTueWedThuFriSat
31123456
78910111213
14151617181920
21222324252627
28293031123
45678910
About the author/Disclaimer

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

© Copyright 2008
Keith Rull
Sign In
Statistics
Total Posts: 260
This Year: 57
This Month: 0
This Week: 0
Comments: 116
Themes
Pick a theme:
Ads
All Content © 2008, Keith Rull
DasBlog theme 'Business' created by Christoph De Baene (delarou)