Registry Folder Sample

This console application has a Shell folder that mimics the Windows Registry Editor ("regedit.exe") in 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. Following 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 (you need to run the sample with enough rights at least once). In this case, we use only three properties:

  • Name (the standard name property)
  • Type (custom property of string type)
  • Value (custom property if string type)


Because Notepad supports fully virtual items, we can even open a key value with Notepad (because values names don't have a .txt type/extension, you have to select "All Files" in the Open Common Dialog to see values):


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):


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 ahead of nonfolders (registry keys) items. Following 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);
}

The sample also demonstrates Explorer notification banners as described in the Information Bar chapter.

Copyright (c) 2022 Callback Technologies, Inc. - All rights reserved.
CBFS Shell 2022 .NET Edition - Version 22.0 [Build 8172]