Ferrysoft Registry Module

Registry Module

Overview

The Ferrysoft Registry Module is a class for manipulating the Registry. The Registry Module is provided in source code form (Visual Basic 2005/2008 compatible and Visual C# 2005/2008 compatible). It is intended for developers, to incorporate into their own applications, in order to provide support to the application for getting, setting and deleting values in the Registry. The module can be used, royalty-free, by any individual or organisation that purchases the module. As the module is provided in source code form, it can be modified as necessary after purchase, provided that any derived module is not distributed, in source code form, to a third party. The module can be incorporated into a commercial product and sold to third parties, in compiled format, provided that the purpose of the commercial product is not simply to act as a wrapper for the Registry Module.

Buy It

The Registry Module is available for download in a password protected zip file. A royalty-free source code licence to use the Registry Module can be purchased. On completion of the purchase, Ferrysoft will email the password of the protected zip file to the purchaser to enable the Registry Module to be extracted for use.

Download

ferrysoft.registry.zip

The Registry Module is priced in Pounds Sterling (GBP), US Dollars (USD) and Euros (EUR).

Ferrysoft Registry Module Price Google PayPal
Royalty-free source code licence (GBP) £49
Royalty-free source code licence (USD) $99 -
Royalty-free source code licence (EUR) €75 -

Summary

The Ferrysoft Registry Module is a wrapper class for the Microsoft.Win32.Registry and Microsoft.Win32.RegistryKey class libraries. It has the following advantages over using the Microsoft.Win32.Registry and Microsoft.Win32.RegistryKey class libraries natively:

  • Encapsulates all references to the Microsoft.Win32.Registry and Microsoft.Win32.RegistryKey class libraries within the class.
  • Provides a default parent key type (typically CurrentUser or LocalMachine) for all class methods.
  • Provides a default sub key (typically formatted as Software\Company, Software\Company\Product or Software\Company\Product\Version) for all class methods.
  • Provides a convenient way of returning a default value if a named value does not exist in the Registry.
  • Provides automatic sub key creation if necessary when setting named values.

Summary of properties provided by the class

The properties provided by the class are described in the following table.

Property Type Use
DefaultParentKeyType ParentKeyType Get/Set the default parent key type for use in methods where the parent key type is not specified. This property is initialised by the New constructor method.
DefaultSubKey String Get/Set the default sub key for use in methods where the sub key is not specified. This property is initialised by the New constructor method.

Summary of methods provided by the class

The methods provided by the class are described in the following table. The permission column specifies the minimum required RegistryPermission to execute the method. There are several variants of each method.

Method Permission Use
GetValue Read Used to return a named string value from the Registry.
SetValue Create and Write Used to set a named string value in the Registry.
DeleteValue Read and Write Used to delete a named value from the Registry.
DeleteSubKey Write Used to delete a sub key from the Registry.
DeleteSubKeyTree Write Used to delete a sub key and any child sub keys recursively from the Registry.

Constructor

Syntax

Visual Basic
Friend Sub New( _
    ByVal ParentKeyType As Ferrysoft.Registry.ParentKeyType, _
    ByVal SubKeyType As Ferrysoft.Registry.SubKeyType)
C#
internal Registry(
    Ferrysoft.Registry.ParentKeyType ParentKeyType,
    Ferrysoft.Registry.SubKeyType SubKeyType)

Parameters

ParentKeyType
The default parent key type for use in methods where the parent key type is not specified. The parameter can be set to any of the following enumerations of Ferrysoft.Registry.ParentKeyType:
ClassesRoot
CurrentConfig
CurrentUser
DynData
LocalMachine
PerformanceData
Users
SubKeyType
The sub key type to specify the format of the default sub key. The default sub key is used in methods where the sub key is not specified. The format of the default sub key can be any of the following (where Company, Product and Version are derived from attributes of the assembly):
Software\Company
Software\Company\Product
Software\Company\Product\Version
The parameter can be set to any of the following enumerations of Ferrysoft.Registry.SubKeyType:
SoftwareCompany
SoftwareCompanyProduct
SoftwareCompanyProductVersion

DefaultParentKeyType property

Syntax

Visual Basic
Friend Property DefaultParentKeyType _
    As Ferrysoft.Registry.ParentKeyType
C#
internal Ferrysoft.Registry.ParentKeyType
    DefaultParentKeyType { get; set; }

Using the DefaultParentKeyType property

Get/Set the default parent key type for use in methods where the parent key type is not specified. This property is initialised by the constructor. The property can be set to any of the following enumerations of Ferrysoft.Registry.ParentKeyType:

ClassesRoot
CurrentConfig
CurrentUser
DynData
LocalMachine
PerformanceData
Users

DefaultSubKey property

Syntax

Visual Basic
Friend Property DefaultSubKey As String
C#
internal string DefaultSubKey { get; set; }

Using the DefaultSubKey property

Get/Set the default sub key for use in methods where the sub key is not specified. This property is initialised by the constructor. An example of a typical sub key is:

Software\Ferrysoft Ltd\Ferrysoft Help Desk\1.0

GetValue methods

Syntax

Visual Basic
Friend Overloads Function GetValue( _
    ByVal Name As String) As String

Friend Overloads Function GetValue( _
    ByVal Name As String, _
    ByVal DefaultValue As String) As String

Friend Overloads Function GetValue( _
    ByVal Name As String, _
    ByVal ParentKeyType As Ferrysoft.Registry.ParentKeyType) _
        As String

Friend Overloads Function GetValue( _
    ByVal Name As String, _
    ByVal DefaultValue As String, _
    ByVal ParentKeyType As Ferrysoft.Registry.ParentKeyType) _
        As String

Friend Overloads Function GetValue( _
    ByVal Name As String, _
    ByVal ParentKeyType As Ferrysoft.Registry.ParentKeyType, _
    ByVal SubKey As String) As String

Friend Overloads Function GetValue( _
    ByVal Name As String, _
    ByVal DefaultValue As String, _
    ByVal ParentKeyType As Ferrysoft.Registry.ParentKeyType, _
    ByVal SubKey As String) As String
C#
internal string GetValue(
    string Name)

internal string GetValue(
    string Name,
    string DefaultValue)

internal string GetValue(
    string Name,
    Ferrysoft.Registry.ParentKeyType ParentKeyType)

internal string GetValue(
    string Name,
    string DefaultValue,
    Ferrysoft.Registry.ParentKeyType ParentKeyType)

internal string GetValue(
    string Name,
    Ferrysoft.Registry.ParentKeyType ParentKeyType,
    string SubKey)

internal string GetValue(
    string Name,
    string DefaultValue,
    Ferrysoft.Registry.ParentKeyType ParentKeyType,
    string SubKey)

Parameters

Name
The name of the value to get from the Registry.
DefaultValue
The default value to return if the named value does not exist. Default is "".
ParentKeyType
The parent key type, for example, Ferrysoft.Registry.ParentKeyType.LocalMachine. The parameter can be set to any of the allowable values for the DefaultParentKeyType property. If the parameter does not exist in the method signature then the DefaultParentKeyType property is used instead.
SubKey
The sub key, for example, "Software\Ferrysoft Ltd\Ferrysoft Help Desk\1.0". The parameter can be set to any format of sub key that is valid for the DefaultSubKey property. If the parameter does not exist in the method signature then the DefaultSubKey property is used instead.

SetValue methods

Syntax

Visual Basic
Friend Overloads Sub SetValue( _
    ByVal Name As String, _
    ByVal Value As String)

Friend Overloads Sub SetValue( _
    ByVal Name As String, _
    ByVal Value As String, _
    ByVal ParentKeyType As Ferrysoft.Registry.ParentKeyType)

Friend Overloads Sub SetValue( _
    ByVal Name As String, _
    ByVal Value As String, _
    ByVal ParentKeyType As Ferrysoft.Registry.ParentKeyType, _
    ByVal SubKey As String)
C#
internal void SetValue(
    string Name,
    string Value)

internal void SetValue(
    string Name,
    string Value,
    Ferrysoft.Registry.ParentKeyType ParentKeyType)

internal void SetValue(
    string Name,
    string Value,
    Ferrysoft.Registry.ParentKeyType ParentKeyType,
    string SubKey)

Parameters

Name
The name of the value to set in the Registry.
Value
The value to set in the Registry.
ParentKeyType
The parent key type, for example, Ferrysoft.Registry.ParentKeyType.LocalMachine. The parameter can be set to any of the allowable values for the DefaultParentKeyType property. If the parameter does not exist in the method signature then the DefaultParentKeyType property is used instead.
SubKey
The sub key, for example, "Software\Ferrysoft Ltd\Ferrysoft Help Desk\1.0". The parameter can be set to any format of sub key that is valid for the DefaultSubKey property. If the parameter does not exist in the method signature then the DefaultSubKey property is used instead.

DeleteValue methods

Syntax

Visual Basic
Friend Overloads Sub DeleteValue( _
    ByVal Name As String)

Friend Overloads Sub DeleteValue( _
    ByVal Name As String, _
    ByVal ParentKeyType As Ferrysoft.Registry.ParentKeyType)

Friend Overloads Sub DeleteValue( _
    ByVal Name As String, _
    ByVal ParentKeyType As Ferrysoft.Registry.ParentKeyType, _
    ByVal SubKey As String)
C#
internal void DeleteValue(
    string Name)

internal void DeleteValue(
    string Name,
    Ferrysoft.Registry.ParentKeyType ParentKeyType)

internal void DeleteValue(
    string Name,
    Ferrysoft.Registry.ParentKeyType ParentKeyType,
    string SubKey)

Parameters

Name
The name of the value to delete from the Registry.
ParentKeyType
The parent key type, for example, Ferrysoft.Registry.ParentKeyType.LocalMachine. The parameter can be set to any of the allowable values for the DefaultParentKeyType property. If the parameter does not exist in the method signature then the DefaultParentKeyType property is used instead.
SubKey
The sub key, for example, "Software\Ferrysoft Ltd\Ferrysoft Help Desk\1.0". The parameter can be set to any format of sub key that is valid for the DefaultSubKey property. If the parameter does not exist in the method signature then the DefaultSubKey property is used instead.

DeleteSubKey methods

Syntax

Visual Basic
Friend Overloads Sub DeleteSubKey()

Friend Overloads Sub DeleteSubKey( _
    ByVal ParentKeyType As Ferrysoft.Registry.ParentKeyType)

Friend Overloads Sub DeleteSubKey( _
    ByVal ParentKeyType As Ferrysoft.Registry.ParentKeyType, _
    ByVal SubKey As String)
C#
internal void DeleteSubKey()

internal void DeleteSubKey(
    Ferrysoft.Registry.ParentKeyType ParentKeyType)

internal void DeleteSubKey(
    Ferrysoft.Registry.ParentKeyType ParentKeyType,
    string SubKey)

Parameters

ParentKeyType
The parent key type, for example, Ferrysoft.Registry.ParentKeyType.LocalMachine. The parameter can be set to any of the allowable values for the DefaultParentKeyType property. If the parameter does not exist in the method signature then the DefaultParentKeyType property is used instead.
SubKey
The sub key, for example, "Software\Ferrysoft Ltd\Ferrysoft Help Desk\1.0". The parameter can be set to any format of sub key that is valid for the DefaultSubKey property. If the parameter does not exist in the method signature then the DefaultSubKey property is used instead.

DeleteSubKeyTree methods

Syntax

Visual Basic
Friend Overloads Sub DeleteSubKeyTree()

Friend Overloads Sub DeleteSubKeyTree( _
    ByVal ParentKeyType As Ferrysoft.Registry.ParentKeyType)

Friend Overloads Sub DeleteSubKeyTree( _
    ByVal ParentKeyType As Ferrysoft.Registry.ParentKeyType, _
    ByVal SubKey As String)
C#
internal void DeleteSubKeyTree()

internal void DeleteSubKeyTree(
    Ferrysoft.Registry.ParentKeyType ParentKeyType)

internal void DeleteSubKeyTree(
    Ferrysoft.Registry.ParentKeyType ParentKeyType,
    string SubKey)

Parameters

ParentKeyType
The parent key type, for example, Ferrysoft.Registry.ParentKeyType.LocalMachine. The parameter can be set to any of the allowable values for the DefaultParentKeyType property. If the parameter does not exist in the method signature then the DefaultParentKeyType property is used instead.
SubKey
The sub key, for example, "Software\Ferrysoft Ltd\Ferrysoft Help Desk\1.0". The parameter can be set to any format of sub key that is valid for the DefaultSubKey property. If the parameter does not exist in the method signature then the DefaultSubKey property is used instead.

Example Use

The code below shows an example of how to use the Registry class. To take advantage of the automatic setting of the DefaultSubKey property in the New constructor, the assembly attributes must be set in the AssemblyInfo.vb (for Visual Basic development) or the AssemblyInfo.cs (for C# development) file. Below is an example of an AssemblyInfo.vb file and an AssemblyInfo.cs file with assembly attributes set for Company, Product and Version.

Visual Basic
<Assembly: _
    System.Reflection.AssemblyCompany("Ferrysoft")>
<Assembly: _
    System.Reflection.AssemblyProduct("Ferrysoft Help Desk")>
<Assembly: _
    System.Reflection.AssemblyVersion("1.0.0.0")>
C#
[assembly:
    System.Reflection.AssemblyCompany("Ferrysoft")]
[assembly:
    System.Reflection.AssemblyProduct("Ferrysoft Help Desk")]
[assembly:
    System.Reflection.AssemblyVersion("1.0.0.0")]

The code below shows an example of how to use the Registry class.

Visual Basic
'
'   This example creates a new Registry object
'   specifying a DefaultParentKeyType of
'   LocalMachine and a DefaultSubKey format of
'   Software\Company\Product\Version.
'
'   It then displays the DefaultSubKey property
'   to demonstrate that the assembly attributes
'   have been used to construct the DefaultSubKey
'   string correctly.
'
'   It then creates an entry named Test containing
'   a test value, retrieves the value to prove that
'   it has been created successfully and then deletes
'   the named value.
'
'   Finally it attempts to retrieve the named value.
'   This time the attempt fails because the value
'   has been deleted. The result is that the default
'   value is returned and displayed instead.
'
Dim Registry As Ferrysoft.Registry
Registry = New Ferrysoft.Registry( _
    Ferrysoft.Registry.ParentKeyType.LocalMachine, _
    Ferrysoft.Registry.SubKeyType. _
        SoftwareCompanyProductVersion)
System.Console.WriteLine(Registry.DefaultSubKey)
Registry.SetValue("Test", "Test Value")
System.Console.WriteLine(Registry.GetValue("Test"))
Registry.DeleteValue("Test")
System.Console.WriteLine(Registry.GetValue("Test", _
    "Default Value"))
C#
//
//  This example creates a new Registry object
//  specifying a DefaultParentKeyType of
//  LocalMachine and a DefaultSubKey format of
//  Software\Company\Product\Version.
//
//  It then displays the DefaultSubKey property
//  to demonstrate that the assembly attributes
//  have been used to construct the DefaultSubKey
//  string correctly.
//
//  It then creates an entry named Test containing
//  a test value, retrieves the value to prove that
//  it has been created successfully and then deletes
//  the named value.
//
//  Finally it attempts to retrieve the named value.
//  This time the attempt fails because the value
//  has been deleted. The result is that the default
//  value is returned and displayed instead.
//
Ferrysoft.Registry Registry;
Registry = new Ferrysoft.Registry(
    Ferrysoft.Registry.ParentKeyType.LocalMachine,
    Ferrysoft.Registry.SubKeyType.
        SoftwareCompanyProductVersion);
System.Console.WriteLine(Registry.DefaultSubKey);
Registry.SetValue("Test", "Test Value");
System.Console.WriteLine(Registry.GetValue("Test"));
Registry.DeleteValue("Test");
System.Console.WriteLine(Registry.GetValue("Test",
    "Default Value"));

When the above code is run it produces the following output:

Software\Ferrysoft\Ferrysoft Help Desk\1.0
Test Value
Default Value