RegistryKeyPermissionCheck.ReadWriteSubTree vs boolean Writable

StewartBW 1,145 Reputation points
2024-07-19T17:11:47.1433333+00:00

Hello,

When using Registry OpenSubKey, I can set either RegistryKeyPermissionCheck.ReadWriteSubTree or Writable boolean property = True.

Using MyKey As RegistryKey = Registry.LocalMachine.OpenSubKey("App.Blah\DefaultIcon", RegistryKeyPermissionCheck.ReadWriteSubTree)

vs

Using MyKey As RegistryKey = Registry.LocalMachine.OpenSubKey("App.Blah\DefaultIcon", True)

After reading RegistryKeyPermissionCheck I could not quite understand it, my app runs in Admin mode, so which one shall I use then? RegistryKeyPermissionCheck.ReadWriteSubTree or True?

Thanks :)

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,011 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,737 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 54,811 Reputation points
    2024-07-19T17:57:55.72+00:00

    For all intents and purposes, they do the same thing. The boolean version is a shortcut for requesting write access while the RegistryKeyPermissionCheck overload allows you to specify specific permissions. But, at least right now, the only permissions are read and write but if they were to add additional options in the future the overload would allow more fine grain control. Under the hood they ultimately both ask for the same permissions and do the same work.

    If you want clean code and then the boolean version is probably the easier to read.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.