How do I take ownership of a registry key via PowerShell?

Viewed 31483

I'm attempting to take ownership of a registry key via PowerShell, and it's failing silently. I'm using the following code:

# get the username of the current user
$uname = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name

# create an identity reference for the owner
$user = new-object System.Security.Principal.NTAccount($uname)

# create a "drive" for HKEY_CLASSES_ROOT
new-psdrive -name HKCR_zf -psprovider Registry -root HKEY_CLASSES_ROOT

# change the current location
set-location HCKR_zf:\CLSID

# set ACLs
(get-acl '{E88DCCE0-B7B3-11d1-A9F0-00AA0060FA31}').setowner($user)

Everything runs fine up to the last line, but the .setowner() call fails silently (the owner is not changed).

How do I take ownership of a registry key?

6 Answers

@Slogmeister and the author of the original, I must say thank you I could not get this sorted. And you helped me do so, just one question, could you elaborate on the logic behind this, what permission structure is above admin, such that an admin trying to take ownership would fail(as it did before your script)? Also, what subsystems are involved and where could one go to learn about them. Ie, what is the script interacting with and how and why :) I know...But it's important to know, as this little exersise proved. I was basically trying to reinstall SSDT and because some key was not allowing alterations it failed, as well as a host of other packages, everything SQL related basically. Thanks a mill, whether you have time to elaborate or not...

Registry::HKEY_CLASSES_ROOT\Installer\Components  

That was the offending key.

Related