# Change Registry Key

**URL:** <https://forums.powershell.org/t/change-registry-key/23866>\
**Category:** PowerShell Help\
**Created:** [March 28, 2024, 8:24pm UTC](https://forums.powershell.org/t/change-registry-key/23866 "2024-03-28T20:24:11Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![jenewa2508](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jenewa2508](https://forums.powershell.org/u/jenewa2508)\
**Post date:** [March 28, 2024, 8:24pm UTC](https://forums.powershell.org/t/change-registry-key/23866/1 "2024-03-28T20:24:11Z")

</div>

Hi, Im trying to change the access of a registry key and its subkeys to READ only for Administrators, while keeping everything else. A new rule is created with only READ access for Administrators, but the original FullControl one is still there. How can I just change the FullControl to Read, to make things easier? Can anyone please help ?

```auto
$key = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey("SYSTEM\MyKey",[Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,[System.Security.AccessControl.RegistryRights]::ChangePermissions)
$acl = $key.GetAccessControl()
$person = [System.Security.Principal.NTAccount]"Administrators"
$access = [System.Security.AccessControl.RegistryRights]"ReadKey"
$inheritance = [System.Security.AccessControl.InheritanceFlags]"ContainerInherit,ObjectInherit"
$propagation = [System.Security.AccessControl.PropagationFlags]"NoPropagateInherit"
$type = [System.Security.AccessControl.AccessControlType]"Allow"
$rule = New-Object System.Security.AccessControl.RegistryAccessRule($person,$access,$inheritance,$propagation,$type)

$acl.SetAccessRuleProtection($True,$False)

$acl.SetAccessRule($rule)
$key.SetAccessControl($acl)

```

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 28, 2024, 9:02pm UTC](https://forums.powershell.org/t/change-registry-key/23866/2 "2024-03-28T21:02:06Z")

</div>

jenewa2508,  
Welcome to the forum. 👋🏼

Did you get this code from an AI? 😏

I’d recommend using the PowerShell cmdlet

> **[Set-Acl (Microsoft.PowerShell.Security) - PowerShell](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-acl?view=powershell-7.4#example-5-grant-administrators-full-control-of-the-file)**
>
> This cmdlet is only available on the Windows platform. The Set-Acl cmdlet changes the security descriptor of a specified item, such as a file or a registry key, to match the values in a security descriptor that you supply. To use Set-Acl, use the...

And you may pay special attention to the example 5.

Regardless of that …

When you post code, sample data, console output or error messages please format it as code using the preformatted text button ( \</\> ). Simply place your cursor on an empty line, click the button and paste your code.

Thanks in advance

[How to format code in PowerShell.org](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/b/bee50c628238f2c076c0504efb6b15f2fb11f002.gif) 1 \<---- Click 👆🏽 😉

( !! Sometimes the _preformatted text_ button hides behind the settings gear symbol. 😉 )

---

<div class="post-metadata">

**Author:** ![jenewa2508](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jenewa2508](https://forums.powershell.org/u/jenewa2508)\
**Post date:** [March 28, 2024, 9:09pm UTC](https://forums.powershell.org/t/change-registry-key/23866/3 "2024-03-28T21:09:33Z")

</div>

I do not know how to change for registry key.

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 29, 2024, 9:53pm UTC](https://forums.powershell.org/t/change-registry-key/23866/4 "2024-03-29T21:53:18Z")

</div>

Have you tried to search for it?

I used this search pattern …

[https://www.google.com/search?q=Powershell+change+acl+for+registry+key](https://www.google.com/search?q=Powershell+change+acl+for+registry+key)

and this is one of the first hits:

> **[How to Change Registry Permissions with PowerShell](https://www.progress.com/blogs/how-to-change-registry-permissions-with-powershell)**
>
> The Windows registry can be a goldmine for attackers and clueless employees.

---

<div class="post-metadata">

**Author:** ![jenewa2508](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jenewa2508](https://forums.powershell.org/u/jenewa2508)\
**Post date:** [March 30, 2024, 7:43pm UTC](https://forums.powershell.org/t/change-registry-key/23866/5 "2024-03-30T19:43:37Z")

</div>

Yes, I have searched other sites for information too, but they talk about different stuff. There are not enough examples to show in the tutorials, too. It is hard to understand.

---

<div class="post-metadata">

**Author:** ![psdarwin](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/psdarwin/32/2063_2.png) [@psdarwin](https://forums.powershell.org/u/psdarwin)\
**Post date:** [April 2, 2024, 1:00pm UTC](https://forums.powershell.org/t/change-registry-key/23866/6 "2024-04-02T13:00:07Z")

</div>

In PowerShell you can navigate the registry like a file system. Try this:

```auto
cd HKLM:\System
Get-ChildItem

```

You should see MyKey there. You can then use Get-ItemProperty and Set-ItemProperty to view and modify registry keys.

Once you find the item you need to modify the ACLs for, you can use Get-ACL and Set-Acl to do that.

---

<div class="post-metadata">

**Author:** ![jenewa2508](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jenewa2508](https://forums.powershell.org/u/jenewa2508)\
**Post date:** [April 3, 2024, 9:34pm UTC](https://forums.powershell.org/t/change-registry-key/23866/7 "2024-04-03T21:34:59Z")

</div>

its not that. I successfully disabled inheritance for registry key, but when I try to just change Administrators permissions to READ only, it creates a whole one, while the original is still there, if you try the script above on a random registry key, you’ll see what I mean. I don’t know what’s missing or wrong

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [April 5, 2024, 2:39pm UTC](https://forums.powershell.org/t/change-registry-key/23866/8 "2024-04-05T14:39:59Z")

</div>

If it applies to a different scope (this folder vs all folders/files) then it will be a different entry.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/9/92813d167a150ae791b3875e5365fe17557b6112.png)  
 ![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/a/a1e0737fdc3161ce22ca26688c4c6ad4a5b921cd.png)

---

<div class="post-metadata">

**Author:** ![jenewa2508](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jenewa2508](https://forums.powershell.org/u/jenewa2508)\
**Post date:** [April 5, 2024, 11:30pm UTC](https://forums.powershell.org/t/change-registry-key/23866/9 "2024-04-05T23:30:25Z")

</div>

This is not about folders, its about registry key. And my script has applied to “This Key and Subkeys”. If you run my script, you will see the error im referring to.

---

<div class="post-metadata">

**Author:** ![krzydoug](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/krzydoug/32/1008_2.png) [@krzydoug](https://forums.powershell.org/u/krzydoug)\
**Post date:** [April 6, 2024, 2:02am UTC](https://forums.powershell.org/t/change-registry-key/23866/10 "2024-04-06T02:02:36Z")

</div>

Ahh my apologies, the example is about ACLs, not folders. I wasn’t aware there was an error. I thought you said “but when I try to just change Administrators permissions to READ only, it creates a whole one, while the original is still there.” Can you clarify the error for me?

---

<div class="post-metadata">

**Author:** ![jenewa2508](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@jenewa2508](https://forums.powershell.org/u/jenewa2508)\
**Post date:** [April 15, 2024, 3:43am UTC](https://forums.powershell.org/t/change-registry-key/23866/12 "2024-04-15T03:43:02Z")

</div>

How do I use these 2 commands on main registry key and recurse thru its subkeys ??

```auto
$acl.SetAccessRuleProtection($True,$False)
$acl.SetAccessRule($rule)

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [May 15, 2024, 3:43am UTC](https://forums.powershell.org/t/change-registry-key/23866/13 "2024-05-15T03:43:54Z")

</div>

Closed on May 15, 2024, 3:43am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
