Microsoft.Win32.Registry.AccessControl 10.0.0-rc.2.25502.107
About
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
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 type provided by this library is:
Microsoft.Win32.RegistryAclExtensions
Additional Documentation
Feedback & Contributing
Microsoft.Win32.Registry.AccessControl is released as open source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.
Showing the top 20 packages that depend on Microsoft.Win32.Registry.AccessControl.
| Packages | Downloads |
|---|---|
|
Microsoft.Windows.Compatibility
This Windows Compatibility Pack provides access to APIs that were previously available only for .NET Framework. It can be used from both .NET as well as .NET Standard.
|
6 |
|
Microsoft.Windows.Compatibility
This Windows Compatibility Pack provides access to APIs that were previously available only for .NET Framework. It can be used from both .NET as well as .NET Standard.
|
7 |
|
System.Management.Automation
PowerShell runtime for hosting PowerShell Core
|
7 |
|
System.Management.Automation
Runtime for hosting PowerShell
|
6 |
|
System.Management.Automation
Runtime for hosting PowerShell
|
7 |
|
System.Management.Automation
Runtime for hosting PowerShell
|
8 |
https://go.microsoft.com/fwlink/?LinkID=799421
.NET Framework 4.6.2
- Microsoft.Win32.Registry (>= 5.0.0)
- System.Security.AccessControl (>= 6.0.0)
.NET 8.0
- No dependencies.
.NET 9.0
- No dependencies.
.NET 10.0
- No dependencies.
.NET Standard 2.0
- Microsoft.Win32.Registry (>= 5.0.0)
- System.Security.AccessControl (>= 6.0.0)