peterlyttle
Technical User
Hello,
I've been fighting with this most of the day and hopefully someone can help me out. Basically I'm trying to remove the BUILTIN\Users account from a system file (C:\Windows\System32\arp.exe) but am getting an error.
Exception calling "SetAccessControl" with "1" argument(s): "Attempted to perform an unauthorized operation."
I've launched my editor as Administrator and have full admin on the PC im working on.
Anyone any ideas?
I've been fighting with this most of the day and hopefully someone can help me out. Basically I'm trying to remove the BUILTIN\Users account from a system file (C:\Windows\System32\arp.exe) but am getting an error.
Exception calling "SetAccessControl" with "1" argument(s): "Attempted to perform an unauthorized operation."
I've launched my editor as Administrator and have full admin on the PC im working on.
Anyone any ideas?
Code:
function DeleteFilePermissions ([string]$Filename, [string]$ACLUsername, [string]$Permission, [string]$Allow_Deny){
$DELACL=Get-Acl $Filename
$DELACL_User = $DELACL.Access | where {$_.IdentityReference -eq "$ACLUsername"}
If ($DELACL_User.IsInherited -eq "True"){
Write-Host -BackgroundColor Black -ForegroundColor Red "Inheritance is ON please resolve this and rerun"
}
else{
If ($DELACL_User.IdentityReference -eq $ACLUsername){
$DELaccessrule = New-Object system.security.AccessControl.FileSystemAccessRule("$ACLUsername","$Permission",,,"$Allow_Deny")
$DELACL.RemoveAccessRuleAll($DELaccessrule)
Set-Acl -aclobject $DELACL $Filename
Write-Host -BackgroundColor Black -ForegroundColor Red "Account Deleted"
}
else{
Write-Host -BackgroundColor Black -ForegroundColor Red "This account does not exsist"
}
}
}
DeleteFilePermissions "C:\Windows\system32\arp.exe" "BUILTIN\Users" "ReadAndExecute" "Allow"