SIGN UP MEMBER LOGIN:    
ARTICLE

How to read Windows Registry?

Posted by Prakash Articles | Current Affairs January 26, 2001
In .NET, the Registry and RegistryKey classes can be used to read and write registry ...
Reader Level:
Download Files:
 

In this article, I will explain how to read Windows Registry. First part of this article explains how to add your own registry entries to test the program.

Here are the step:

Add Registry Data

Following text is a actual registry information. Copy and paste this content in a text file and save as with extention .reg. and double click on the file.

/*Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\TAW\BSE]
"DSN"="TAWReports"
"User"="TAW1"
"Password"="taw1.1"
"Server"="dbserver"
"IP"=""
*/


Read the Registry Data

  1. Create two RegistryKey variables.
  2. Create object od sealed class as shown below with first parameter as HKEY (main root key name) and second as "" for local machine.
  3. Create sub key from where one would like to read information.
  4. Use Getvalue method of RegistryKey class for reading data for a particular node key information. Here DSN,Server,Password are nodes.

This source code reads the registry data which you have just added to your registry.

namespace CONAPP
{
using System;
using Microsoft.Win32;
public class Class1
{
public Class1()
{
//
// TODO: Add Constructor Logic here
//
}
public static int Main(string[] args)
{
RegistryKey SUBKEY;
RegistryKey TAWKAY = RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.CurrentUser,"");
string subkey = "Software\\TAW\\BSE";
SUBKEY = TAWKAY.OpenSubKey(subkey);
object dsn = SUBKEY.GetValue("DSN");
object user = SUBKEY.GetValue("user");
object password = SUBKEY.GetValue("password");
object server = SUBKEY.GetValue("server");
return 0;
}
}
}

Login to add your contents and source code to this article
share this article :
post comment
 

vbnvbnvbnvn

Posted by Swadhin Mohanta Oct 01, 2010
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor