Registry Folder sample

Source repository: https://github.com/aelyo-softworks/ShellBoost-Samples

A Console application shell folder that mimics the Windows Registry Editor (“regedit.exe”) in Windows Explorer with only virtual shell items. You can read and rename keys and values using standard shell UI, and you can create and edit keys and values, using a regedit.exe-like UI written using Winforms.

Shell Items representing values have the same icons as regedit.exe. Two .NET icons have been added to the project as embedded resources. This is the corresponding code:

Thumbnail = new AssemblyResourceShellThumbnail(Parent.Root.Server, GetType().Namespace + ".Resources." + (iconIsString ? "REG_SZ.ico" : "REG_BINARY.ico"));

The sample also demonstrates how to declare and register custom properties (so you need to run the sample with sufficient rights at least once). In this case, we only use 3 properties:

Name (the standard name property)

Type (custom property of String type)

Value (custom property if String type)

Registry Folder sample - Picture 48

Because notepad supports fully virtual items, we can even open a key value with notepad (since values names don’t have a .txt type/extension, you’ll have to select “All Files” in the Open common dialog to be able to see values):

Registry Folder sample - Picture 49

If you press “Open”, notepad will open the value as the item content (but you won’t be able to save it back since it’s a fully virtual item):

Registry Folder sample - Picture 51

This is the corresponding code:

public override ShellContent GetContent() => new MemoryShellContent(Data?.ToString());

The sample also demonstrates a custom comparison between shell items in a folder: the (default) item (registry value) always appears first of non-folders (registry keys) items. This is the corresponding code:

protected override bool TryCompare(ShellItem other, ShellFolderColumn column, out CompareIdReturnValue value)
{
    if (other is RegistryValueItem otherValue)
    {
        if (IsDefault)
        {
            if (otherValue.IsDefault)
            {
                value = CompareIdReturnValue.LeftEqualsRight;
                return true;
            }
 
            value = CompareIdReturnValue.LeftPrecedesRight;
            return true;
        }
        else if (otherValue.IsDefault)
        {
            value = CompareIdReturnValue.LeftFollowsRight;
            return true;
        }
    }
    return base.TryCompare(other, column, out value);
}