如何通过 PowerShell 获得注册表项的所有权? [英] How do I take ownership of a registry key via PowerShell?
问题描述
我正在尝试通过 PowerShell 获取注册表项的所有权,但它无声无息地失败了.我正在使用以下代码:
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)
直到最后一行都运行良好,但 .setowner() 调用无声地失败(所有者未更改).
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?
推荐答案
仅调用 SetOwner
不会提交更改.您需要将 acl 对象传递回 Set-Acl
以提交更改.
Just calling SetOwner
doesn't commit the change. You need to pass the acl object back to Set-Acl
to commit the change.
看看这个线程,有一个很好的描述和完整的示例代码.似乎还有其他一些障碍需要跳过:http://social.technet.microsoft.com/Forums/en/winserverpowershell/thread/e718a560-2908-4b91-ad42-d392e7f8f1ad
Check out this thread, there is a good description and full sample code. Seems there are some other hoops to jump through, as well: http://social.technet.microsoft.com/Forums/en/winserverpowershell/thread/e718a560-2908-4b91-ad42-d392e7f8f1ad
这篇关于如何通过 PowerShell 获得注册表项的所有权?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!