9

I have a Windows PowerShell script. I logged into Windows as an administrator and run the script with PowerShell running as an administrator, and it worked; I could see all the changes happen after running this script.

But I still get the red error message:

requested registry access is not allowed

which is driving me nuts.

Why am I getting this error and how can I make it go away?

TylerH
  • 20,799
  • 66
  • 75
  • 101
Ryan Wang
  • 165
  • 1
  • 2
  • 6
  • 3
    Which part of the registry is it complaining about? Some of the registry is owned by `TrustedInstaller`. Administrator is not enough. – Roger Lipscombe Mar 27 '13 at 17:09
  • Does this answer your question? [Set-Acl : Requested registry access is not allowed](https://stackoverflow.com/questions/24366162/set-acl-requested-registry-access-is-not-allowed) – chx May 29 '21 at 07:57

3 Answers3

6

If you run regedit and navigate to the key that you are trying to access with your script, you can right click on it and view the permissions. You can see on that key what permissions Administrator has (Full Control, Read, Special Permissions)

PlantationGator
  • 815
  • 1
  • 13
  • 21
2

Try as Local System via psexec

This here worked for me:

StackzOfZtuff
  • 2,534
  • 1
  • 28
  • 25
1

This PowerShell trick worked for me:

$Path = "SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.jpeg\UserChoice"
$SubKey = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($Path, [Microsoft.Win32.RegistryKeyPermissionCheck]::ReadWriteSubTree, [System.Security.AccessControl.RegistryRights]::ChangePermissions)
$Acl = $SubKey.GetAccessControl()
$RemoveAcl = $Acl.Access | Where-Object {$_.AccessControlType -eq "Deny"}
$Acl.RemoveAccessRule($RemoveAcl)
$SubKey.SetAccessControl($Acl)
$SubKey.Close()

**in $Path ==> change this to your path (path after Root folder)

**in $SubKey ==> [Microsoft.Win32.Registry]::CurrentUser : change this to your needed root Registry path

  • This often doesn't work because you are not elevated https://stackoverflow.com/a/35844259/308851 does the job. – chx May 29 '21 at 07:57