Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run as administrator, but still "requested registry access is not allowed"

Tags:

powershell

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?

like image 769
Ryan Wang Avatar asked Mar 27 '13 17:03

Ryan Wang


3 Answers

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)

like image 89
PlantationGator Avatar answered Sep 21 '22 15:09

PlantationGator


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

like image 37
Milad Fadavvi Avatar answered Sep 21 '22 15:09

Milad Fadavvi


Try as Local System via psexec

This here worked for me:

  • get psexec.exe from here: https://docs.microsoft.com/en-us/sysinternals/downloads/psexec
  • use psexec.exe -i -s powershell.exe to start a new interactive (-i parameter) powershell.exe window as user Local System (-s parameter).
  • Inside that new powershell window try your command again.
like image 39
StackzOfZtuff Avatar answered Sep 17 '22 15:09

StackzOfZtuff