PowerShell – Change Registry Key Permissions

email me

$regPath = "HKLM:\SOFTWARE\JavaSoft"

Try  {
        Get-ItemProperty $regPath -ErrorAction Stop        
        $regACL = Get-ACL $regPath
        $regRule= New-Object System.Security.AccessControl.RegistryAccessRule("Everyone","ReadPermissions","Allow")
        #("Everyone","FullControl","Allow")
        $regACL.SetAccessRule($regRule)
        Set-Acl $regPath $regACL
        Write-Host "Success!"
      }

Catch {
            
         Write-Host "Failed!"
      }

Notes

$x = $regACL.AccessRightType.IsPublic
if ($x -eq "True" ) {write-host "Success"}

$regKey = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey("SOFTWARE\JavaSoft",[Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree,[System.Security.AccessControl.RegistryRights]::ChangePermissions)
$regACL = $regKey.GetAccessControl()
$regRule = New-Object System.Security.AccessControl.RegistryAccessRule ("User","FullControl","Allow")
$regACL.SetAccessRule($regRule)
$regKey.SetAccessControl($regACL)