使用PowerShell设置注册表项所有者和写入权限

时间:2019-06-13 17:10:49

标签: powershell acl

我正在尝试在不使用GUI的情况下修改用户的帐户图片。如果我将所有者设置为当前用户(管理员),并使用GUI将“所有人”的权限设置为“ FullControl”,则设置图标的代码的第二部分工作正常。我尝试更改“所有人”的注册表项规则的第一部分给我错误“ Set-Acl:不允许请求的注册表访问”。

我尝试使用openSubKey(),但也没有采用这种方法。

#French Accessible
$UserAFR = New-Object System.Security.Principal.NTAccount("FrançaisAccessible")
$ADuserAFR_sid = $UserAFR.Translate([System.Security.Principal.SecurityIdentifier]).Value
$reg_base_afr = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AccountPicture\Users\$ADuserAFR_sid"

$curUser = New-Object System.Security.Principal.NTAccount($env:UserDomain, $env:UserName)

$acl = Get-Acl HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AccountPicture\Users\$ADuserAFR_sid
$acl.SetOwner($curUser)
$acl.SetAccessRuleProtection($False, $False)

$person = [System.Security.Principal.NTAccount]"Everyone"
$access = [System.Security.AccessControl.RegistryRights]"FullControl"
$inheritance = [System.Security.AccessControl.InheritanceFlags]"ObjectInherit, ContainerInherit"
$propagation = [System.Security.AccessControl.PropagationFlags]"None"
$type = [System.Security.AccessControl.AccessControlType]"Allow"

$rule = New-Object System.Security.AccessControl.RegistryAccessRule($person,$access,$inheritance,$propagation,$type)
$acl.ResetAccessRule($rule)

#Gets Error Message Saying Set-Acl: requested registry access is not allowed
Set-Acl HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AccountPicture\Users\$ADuserAFR_sid $acl

#Claims to say that everyone has FullControl
$acl.GetAccessRules($true,$true, [System.Security.Principal.NTAccount])

#Check to see if RegistryIdentity is set to FullControl
(Get-Acl HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AccountPicture\Users\$ADuserAFR_sid).Access | Format-Table -Wrap

#####################################
## Set Icons - Francais Accessible ##
#####################################
$img448_afr_base = "C:\Company\Profiles\AFR\flat_afr_448.jpg"
$img240_afr_base = "C:\Company\Profiles\AFR\flat_afr_240.jpg"
$img192_afr_base = "C:\Company\Profiles\AFR\flat_afr_192.jpg"
$img96_afr_base = "C:\Company\Profiles\AFR\flat_afr_96.jpg"
$img48_afr_base = "C:\Company\Profiles\AFR\flat_afr_48.jpg"
$img40_afr_base = "C:\Company\Profiles\AFR\flat_afr_40.jpg"
$img32_afr_base = "C:\Company\Profiles\AFR\flat_afr_32.jpg"

Set-ItemProperty -Force -Path $reg_base_afr -Name Image448 -Value $img448_afr_base
Set-ItemProperty -Force -Path $reg_base_afr -Name Image240 -Value $img240_afr_base
Set-ItemProperty -Force -Path $reg_base_afr -Name Image192 -Value $img192_afr_base
Set-ItemProperty -Force -Path $reg_base_afr -Name Image96 -Value $img96_afr_base
Set-ItemProperty -Force -Path $reg_base_afr -Name Image48 -Value $img48_afr_base
Set-ItemProperty -Force -Path $reg_base_afr -Name Image40 -Value $img40_afr_base
Set-ItemProperty -Force -Path $reg_base_afr -Name Image32 -Value $img32_afr_base

我希望Set-Acl将“注册表身份”权限设置为FullControl。 即使将所有者设置为当前用户(管理员),我也无法访问注册表项。

0 个答案:

没有答案
相关问题