This script adds 'Take Ownership' to the context menu in Windows 8.
When you want to delete and copy some files and folders in Windows 8, you may encounter a "you do not have permission to delete or move it” message. This occurs because you are not the owner of the file or folder. This script adds "take ownership" to the context menu so that you can easily change the owner of a file to the current user.
This script contains the Set-OSCTakeOwnerShip advanced function. You can use this script in the following ways:
Method 1:
Method 2:
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
If(Test-Path -LiteralPath 'HKCR:\*\shell\runas')
{
Set-Location -LiteralPath 'HKCR:\*\shell'
Remove-Item -Path ".\runas" -Recurse -Confirm:$false
}
If(Test-Path -LiteralPath 'HKCR:\Directory\shell\runas' )
{
Set-Location -LiteralPath 'HKCR:\Directory\shell'
Remove-Item -Path ".\runas" -Recurse -Confirm:$false
}
If(Test-Path -LiteralPath 'HKCR:\dllfile\shell' )
{
Set-Location -Path 'HKCR:\dllfile\'
Remove-Item -Path ".\shell" -Recurse -Confirm:$false
}
Set-Location (Split-Path $env:ComSpec -Parent)
Write-Host "Remove 'Take ownership' from context menu successfully."
If(Test-Path-LiteralPath 'HKCR:\*\shell\runas') { Set-Location-LiteralPath 'HKCR:\*\shell'Remove-Item-Path ".\runas"-Recurse -Confirm:$false } If(Test-Path-LiteralPath 'HKCR:\Directory\shell\runas' ) { Set-Location-LiteralPath 'HKCR:\Directory\shell'Remove-Item-Path ".\runas"-Recurse -Confirm:$false } If(Test-Path-LiteralPath 'HKCR:\dllfile\shell' ) { Set-Location-Path 'HKCR:\dllfile\' Remove-Item-Path ".\shell"-Recurse -Confirm:$false } Set-Location (Split-Path$env:ComSpec -Parent) Write-Host "Remove 'Take ownership' from context menu successfully."
Example 1: Add 'Take Ownership' to context menu.
Command: Set-OSCTakeOwnerShip -Add
Screenshot:

Example 2: Remove 'Take Ownership' from context menu.
Command: Set-OSCTakeOwnerShip -Remove
Screenshot:

Windows 8