diff --git a/src/libraries/Microsoft.Win32.Registry.AccessControl/src/PACKAGE.md b/src/libraries/Microsoft.Win32.Registry.AccessControl/src/PACKAGE.md index 4e35cf443fad59..8190854cfa8300 100644 --- a/src/libraries/Microsoft.Win32.Registry.AccessControl/src/PACKAGE.md +++ b/src/libraries/Microsoft.Win32.Registry.AccessControl/src/PACKAGE.md @@ -2,43 +2,69 @@ - +Provides support for managing access control lists for `Microsoft.Win32.RegistryKey`. ## Key Features -* -* -* +* Get access control lists for a registry key. +* Get a specific sections of an access control list. +* Set the access control list for a registry key. ## How to Use +```csharp +using Microsoft.Win32; +using System.Security.AccessControl; + +// Open a registry key (or create it if it doesn't exist) +using RegistryKey registryKey = Registry.CurrentUser.CreateSubKey("TestKey"); +if (registryKey == null) +{ + Console.WriteLine("Failed to create or open the registry key."); + return; +} + +// Get the current access control list (ACL) for the registry key +RegistrySecurity registrySecurity = registryKey.GetAccessControl(); +Console.WriteLine("Current Access Control List (ACL):"); +Console.WriteLine(registrySecurity.GetSecurityDescriptorSddlForm(AccessControlSections.Access)); + +// Create a new access rule granting full control to the current user +string currentUser = Environment.UserName; +RegistryAccessRule accessRule = new RegistryAccessRule(currentUser, RegistryRights.FullControl, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow); + +// Add the new access rule to the ACL +registrySecurity.AddAccessRule(accessRule); + +// Set the updated ACL on the registry key +registryKey.SetAccessControl(registrySecurity); + +// Get and display the updated ACL for the registry key using the second GetAccessControl overload +RegistrySecurity updatedRegistrySecurity = registryKey.GetAccessControl(AccessControlSections.Access); +Console.WriteLine("Updated Access Control List (ACL):"); +Console.WriteLine(updatedRegistrySecurity.GetSecurityDescriptorSddlForm(AccessControlSections.Access)); +``` + ## Main Types -The main types provided by this library are: +The main type provided by this library is: -* `` -* `` -* `` +* `Microsoft.Win32.RegistryAclExtensions` ## Additional Documentation -* [Conceptual documentation](https://learn.microsoft.com/dotnet/standard/serialization/**LIBRARYNAME**/overview) -* [API documentation](https://learn.microsoft.com/dotnet/api/**LIBRARYNAME**) - -## Related Packages - - +* [API documentation](https://learn.microsoft.com/dotnet/api/microsoft.win32.registryaclextensions) ## Feedback & Contributing -Microsoft.Win32.Registry.AccessControl is released as open source under the [MIT license](https://licenses.nuget.org/MIT). Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/runtime). \ No newline at end of file +Microsoft.Win32.Registry.AccessControl is released as open source under the [MIT license](https://licenses.nuget.org/MIT). Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/runtime).