Esatto.Win32.Registry 3.0.17

dotnet add package Esatto.Win32.Registry --version 3.0.17                
NuGet\Install-Package Esatto.Win32.Registry -Version 3.0.17                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Esatto.Win32.Registry" Version="3.0.17" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Esatto.Win32.Registry --version 3.0.17                
#r "nuget: Esatto.Win32.Registry, 3.0.17"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Esatto.Win32.Registry as a Cake Addin
#addin nuget:?package=Esatto.Win32.Registry&version=3.0.17

// Install Esatto.Win32.Registry as a Cake Tool
#tool nuget:?package=Esatto.Win32.Registry&version=3.0.17                

Esatto Win32 Registry

Allows use of Registry to store config and preferences via MEDC or wrapper classes.

Microsoft.Extensions.Configuration

Use IConfigurationBuilder.AddRegistry to incorporate values from the registry into MEDC. Keys created under the path specified will be added as values will be added recursively. On non-windows platforms (Linux, MacOS) the call has no effect.

Example registry settings:

Set-ItemProperty -Path "HKLM:\Software\Company Name\Product" -Name "Setting1" -Value "Example value" -Type String

Example use:

var builder = WebApplication.CreateBuilder(args);
builder.Configuration
    .AddRegistry(@"Software\Company Name\Product")
    .AddJsonFile("appsettings.json", optional: true)
    .AddEnvironmentVariables();

var exampleConfig = builder.Configuration.GetSection("Example").Get<ExampleAppSettings>();
Assert.AreEqual("Example value", exampleConfig?.Setting1);

class ExampleAppSettings 
{
    public string? Setting1 { get; set; }
}

Wrapper classes

Inherit from RegistrySettings to create a wrapper class that exposes a key for read/write. Writes are only made to HKCU. Changes are monitored and trigger events. Reads are "live" so setting changes in one app are immediately available in other copies of the app.

Types supported:

Registry Type .Net Type Get Set
REG_DWORD int GetInt SetInt
REG_DWORD (1 or 0) bool (value != 0) GetBool SetBool
REG_DWORD (milliseconds) TimeSpan GetTimeSpan SetTimeSpan
REG_SZ string GetString SetString
REG_SZ Guid GetGuid SetGuid
REG_SZ (enum.ToString()) Enum (enum.Parse) GetEnum<T> SetEnum<T>
REG_EXPAND_SZ string[] GetMultiString SetMultiString

Settings are pulled in via first match from:

  1. User Group Policy (HKCU\Policies\{Path})
  2. Computer Group Policy (HKLM\Policies\{Path})
  3. User registry (HKCU\{Path})
  4. Computer registry (HKLM\{Path})

Example use:

Console.WriteLine(ExampleSettings.Instance.ReceiptCodeValidityPeriod);
ExampleSettings.Instance.ServerName = "example.com";

internal sealed class ExampleSettings : RegistrySettings
{
    public static ExampleSettings Instance { get; } = new();

    public ExampleSettings()
        : base(@"Company Name\Product Name")
    {
    }

    public int ReceiptCodeValidityPeriod
    {
        get => GetInt(nameof(ReceiptCodeValidityPeriod), 60);
        set => SetInt(nameof(ReceiptCodeValidityPeriod), value);
    }

    public string ServerName
    {
        get => GetString(nameof(ServerName), null);
        set => SetString(nameof(ServerName), value);
    }

    public bool AutoConnect
    {
        get => GetBool(nameof(AutoConnect), false);
        set => SetBool(nameof(AutoConnect), value);
    }

    public string[] RecentDocuments
    {
        get => GetBool(nameof(RecentDocuments), new string[0]);
        set => SetBool(nameof(RecentDocuments), value);
    }
}

Subkeys may be exposed as nested RegistrySettings instances to permit lists / dictionaries.

ADMX Export for Wrapper Classes

Wrapper classes may be exported to admx files for use in Group Policy. Add the nuget package Esatto.Win32.Registry.AdmxExporter to the project containing the wrapper classes. Annotate the settings with [DisplayName("Setting Name")] and other attributes to make things pretty. See AdmxExporter for more details.

<ItemGroup>
    <PackageReference Include="Esatto.Win32.Registry" Version="3.0.5" />
    <PackageReference Include="Esatto.Win32.Registry.AdmxExporter" Version="3.0.5" />
</ItemGroup>

Example appearance in Group Policy Management Center (GPMC):

Group Policy Management Center showing the loaded ADMX file

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Esatto.Win32.Registry:

Package Downloads
Itp.WpfScanners

Keyboard-like incorporation of barcode scanners into WPF applications. Support for Serial and HID barcode scanners.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.17 175 7/14/2024
3.0.6 314 11/12/2023
3.0.4 116 11/9/2023
3.0.3 142 11/4/2023
3.0.2 157 10/31/2023
3.0.1 193 7/4/2023
3.0.0 198 4/29/2023
1.0.1 284 4/20/2023
1.0.0 190 4/20/2023