Skip to content

Add key_options/key_disposition support to create_*_key helpers#640

Open
benhillis wants to merge 1 commit into
microsoft:masterfrom
benhillis:reg-create-key-options
Open

Add key_options/key_disposition support to create_*_key helpers#640
benhillis wants to merge 1 commit into
microsoft:masterfrom
benhillis:reg-create-key-options

Conversation

@benhillis

Copy link
Copy Markdown
Member

Adds key_options (volatile) and key_disposition (created vs opened-existing) support to the create_*_key[_nothrow] helpers. Includes Catch2 [registry] tests passing in normal & noexcept configs. Part of enabling WSL to drop its in-house registry helper in favor of wil::reg.

@benhillis benhillis force-pushed the reg-create-key-options branch from fd100b1 to 07a859c Compare June 12, 2026 15:40
@benhillis benhillis marked this pull request as ready for review June 18, 2026 17:22
Comment on lines +87 to +95
// Options controlling how a key is created. See the dwOptions parameter of RegCreateKeyExW.
enum class key_options
{
// The key is preserved when the system is restarted (REG_OPTION_NON_VOLATILE).
non_volatile,

// The key is not preserved when the system is restarted (REG_OPTION_VOLATILE).
is_volatile,
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally just assign these to their values and specify the size of the enum so this can just be a static_cast

Suggested change
// Options controlling how a key is created. See the dwOptions parameter of RegCreateKeyExW.
enum class key_options
{
// The key is preserved when the system is restarted (REG_OPTION_NON_VOLATILE).
non_volatile,
// The key is not preserved when the system is restarted (REG_OPTION_VOLATILE).
is_volatile,
};
// Options controlling how a key is created. See the dwOptions parameter of RegCreateKeyExW.
enum class key_options : DWORD
{
// The key is preserved when the system is restarted (REG_OPTION_NON_VOLATILE).
non_volatile = REG_OPTION_NON_VOLATILE,
// The key is not preserved when the system is restarted (REG_OPTION_VOLATILE).
is_volatile = REG_OPTION_VOLATILE,
};

Extend the wil::reg create-key helpers so callers can request a volatile
key and observe whether the key was newly created:

- New key_options enum (non_volatile / is_volatile) mapped to the
  RegCreateKeyExW dwOptions parameter.
- New key_disposition enum (created_new / opened_existing) surfaced via
  an optional out-parameter that mirrors lpdwDisposition.

create_unique_key, create_shared_key, and their _nothrow counterparts
gain defaulted options/disposition parameters, so existing call sites are
unaffected. Adds RegistryTests coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@benhillis benhillis force-pushed the reg-create-key-options branch from b5860b0 to c1e04f3 Compare July 8, 2026 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants