# Setting permissions on Registry Key

**URL:** <https://forums.powershell.org/t/setting-permissions-on-registry-key/14622>\
**Category:** PowerShell Help\
**Created:** [July 2, 2020, 4:35am UTC](https://forums.powershell.org/t/setting-permissions-on-registry-key/14622 "2020-07-02T04:35:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmoods](https://avatars.discourse-cdn.com/v4/letter/j/919ad9/32.png) [@jmoods](https://forums.powershell.org/u/jmoods)\
**Post date:** [July 2, 2020, 4:35am UTC](https://forums.powershell.org/t/setting-permissions-on-registry-key/14622/1 "2020-07-02T04:35:52Z")

</div>

I’m converting a bat file to PowerShell and can’t figure out how to set permissions on a Registry Key. I’m trying to use subinacl.exe to do this.

Here is the command that I was using in the bat file.

`“%~dp0subinacl.exe” /subkeyreg “HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Test Key” /grant=“Everyone”=F`

Here is what I am trying in PowerShell

`$filespath = (Split-Path $MyInvocation.Mycommand.Path)`

`$testargsacl = @(“/subkeyreg 'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Test Key”, “/grant=“Everyone”=F”)`

`Start-Process -filepath ($filespath + ‘\subinacl.exe’) -ArgumentList $testargsacl -wait`

At C:\Temp\Test\Install.ps1:21 char:109

- … OFTWARE\Wow6432Node\Test Com’", “/grant=“Everyon”=F”)
- 

```auto

```

Unexpected token ‘Everyon"=F"’ in expression or statement.

- CategoryInfo : ParserError: (🙂 , ParentContainsErrorRecordException
- FullyQualifiedErrorId : UnexpectedToken

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [July 2, 2020, 8:51pm UTC](https://forums.powershell.org/t/setting-permissions-on-registry-key/14622/2 "2020-07-02T20:51:34Z")

</div>

You can use ACL cmdlets in PowerShell like below to achieve this.

```
$Acl = Get-Acl -Path $RegistryPath
$ACLItem = New-Object -TypeName System.Security.AccessControl.RegistryAccessRule($UserName, [System.Security.AccessControl.RegistryRights]::ReadKey, "ContainerInherit,ObjectInherit", "None", "Allow")
$Acl.SetAccessRule($ACLItem)
Set-Acl -Path $RegistryPath -ACLObject $Acl
```

---

<div class="post-metadata">

**Author:** ![gnart](https://avatars.discourse-cdn.com/v4/letter/g/5e9695/32.png) [@gnart](https://forums.powershell.org/u/gnart)\
**Post date:** [July 5, 2020, 8:05am UTC](https://forums.powershell.org/t/setting-permissions-on-registry-key/14622/3 "2020-07-05T08:05:04Z")

</div>

PowerShell returned and pointed to the error in the code.  
Breaking down the code, please notice the error in the opening single quote (end of second ine) without a matching closing single quote, as follow:  
`$testargsacl = @(“`  
`/subkeyreg '`  
`HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Test Key”, “/grant=“Everyone”=F`  
`”)`

---

<div class="post-metadata">

**Author:** ![jmoods](https://avatars.discourse-cdn.com/v4/letter/j/919ad9/32.png) [@jmoods](https://forums.powershell.org/u/jmoods)\
**Post date:** [July 7, 2020, 12:44pm UTC](https://forums.powershell.org/t/setting-permissions-on-registry-key/14622/4 "2020-07-07T12:44:42Z")

</div>

Thanks, I tried closing the quote and it still fails. I cleaned up the quotes on the end of the variable so now i’m not getting an error in powershell when running this and it is now running the subinacl.exe but is failing because there is a space in the Registry Key path.

To be honest I’m having a hard time understanding how to deal with spaces in powershell. I created a Registry Key simply called Test and the code below does work but unfortunately the software I am working with has spaces in the Key name. Any idea what I can do to get it to work on a Key named “Test Key”?

$testargsacl = @(“/subkeyreg HKEY\_LOCAL\_MACHINE\SOFTWARE\Wow6432Node\Test”, “/grant=Everyone=F”)  
Start-Process -filepath ($filespath + ‘\subinacl.exe’) -ArgumentList $testargsacl

---

<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:** [July 7, 2020, 7:52pm UTC](https://forums.powershell.org/t/setting-permissions-on-registry-key/14622/5 "2020-07-07T19:52:25Z")

</div>

I don’t understand why you aren’t trying the powershell way that kvprasoon provided. That said, I recommend you use splatting for your command arguments. This works for me.

```
$cmdargs = @("/subkeyreg","HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Test Key",'/grant="Everyone"=F')
.\subinacl.exe @cmdargs
```

output

```
SOFTWARE\Wow6432Node\Test Key : new ace for \everyone
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Test Key : 1 change(s)

Elapsed Time: 00 00:00:00
Done: 1, Modified 1, Failed 0, Syntax errors 0
Last Done : HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Test Key
```

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/setting-permissions-on-registry-key/14622/6 "2024-05-16T20:29:16Z")

</div>

Closed on May 16, 2024, 8:29pm UTC


