Windows Registry Classes

Last Update
28 March 2010
Regular License
$20
Extended License
$100
Sales
3

Introduction

The Windows Registry is a hierarchical database that stores settings and configurations for applications, device drivers, services, the kernel and more. These three classes are intended to ease the use of Windows Registry, and they can easily become a part of any application you might be working on.

CoreRegistry: Gets and sets keys and their value to the Registry. Converts objects to binary

SimpleRegistry: Simplifies the useage of Registry when developing large software

AdvancedRegistry: Shows how to store objects such as Image and a custom class to Registry

Features

Basic types such as int, bool and string are supported Objects such as DateTime, Image and Color are supported Start any program with Windows with only one line of code Arrays or Lists can easily are transformed and stored Enum values are supported as key names, and example is given You can easily add support for direct casting of objects if needed

How to use

Simple and Advanced classes are initalized with a program and company name. These strings will determine the location of the keys in Registry.

SimpleRegistry reg = new SimpleRegistry("MyProgram", "MyCompany"); AdvancedRegistry adv = new AdvancedRegistry("MyProgram", " MyCompany");

Core offers more constructor overloads to set the location, and can be directed to any location if you want to read keys set by another program.

CoreRegistry reg = new CoreRegistry(RegistryClasses.LocalMachine, @"SOFTWARE\MyCompany\MyProgram\SpecialKeys");

Advanced class offers you a way to store an array of strings, start your application with Windows and save an Image object to Registry.

adv.SetNameList(textBox1.Lines); adv.StartUpWithWindows = true; adv.SetImage(pictureBox1.Image);

Simple class offers you a way to extend the Core class functionality to more readable code and good maintenance for your settings.

reg.SomeBoolean = checkBox1.Checked; reg.SomeColor = label1.BackColor; reg.SomeDateTime = dateTimePicker1.Value; reg.SomeInteger = numericUpDown1.Value; reg.SomeString = textBox1.Text;

if(reg.SomeBoolean && reg. SomeInteger > 10) { reg.SomeString = "Something else…"; }

What do you gain from using these classes

Type-casting: The RegistryKey class in the Microsoft.Win32 namespace can only store objects and retrive objects. When a string is stored and retrived, it is returned as an object and needs to be casted to string. Same goes for all other types and objects, you constantly have to do some casting which these classes are doing for you.

Readability: When you have an application that needs to store large amount of settings and configuration, you want to make the source-code as readable as possible and keep the number of lines to a minimum. Using these classes achives that goal.

Maintanence Keeping all the Registry interaction in one or two classes not only makes your application more readable, but also improves maintanence and makes it easier for you to add new features and functionality that need Registry storage.

Hierarchy If the scenario is that you have a “global library” that number of applications use, you could have CoreRegistry in that global library and mixture of SimpleRegistry and AdvancedRegistry in the applications. Then when a feature or data type is needed , the CoreRegistry would be extended enabling all the other applications to use that feature seamlessly.