Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Issues with taking ownership and set-acl

$
0
0

I am trying to set the corporate desktop background for a Win 8 build. I understand there are two files called img0.jpg that need to be replaced. I have two issues, first is finding the files and loading into an variable, second is getting access to the file because it is owned by Trusted installer

Checking out some articles I hoped this would work

 
$Filepath = "C:\Windows\web\wallpaper\windows"
$Filename = $filepath + "\img0.jpg"

setaccess $Filename

Copy-Item -path '.\img0.jpg' -destination $filepath -Force

$Filename = "C:\Windows\WinSxS\x86_microsoft-windows-s..l-wallpaper-windows_31bf3856ad364e35_6.3.9600.16384_none_6fb1eabbcc0b541d"
setaccess $Filename
Copy-Item -path '.\img0.jpg' -destination $img0path -Force

function setaccess
{
 param($FileName)
  
 &takeown /F $FileName
 $User = [System.Security.Principal.WindowsIdentity]::GetCurrent().User
 $Acl = Get-Acl $FileName
 $Acl.SetOwner($User)
 $AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($User, "FullControl", "Allow")
 $Acl.SetAccessRule($AccessRule)
 Set-Acl $FileName $Acl

}
 

I find that the takeown.exe works ok and that the file ownership has correctly changed to my logged on account (Administrator), but when issuing the set-acl command I get error "attempting to perform an unauthorised operation" and permission denied, which If I'm now the owner I should be able to set permissions?? - I can do it from windows explorer gui now I'm the owner

Second - once I get this sorted out I need to search C:\windows to find the exact directory locations for each of these files - I had tried command like get-childitem -path c:\windows -recurse -filter 'img0.jpg' which does return the information but I need to load them up into a usable variable that I can then call the above code to take ownership

any advice welcome - thanks


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>