Introduction
This guide demos 2 methods to take ownership of folder in Windows 10.
Options to Take Ownership of Folder in Windows 10
Here are the 2 methods to take Ownership of folder in Windows 10 discussed in this guide:
- Folder Security Properties
- Command Prompt
Take Ownership of Folder in Windows 10 from Folder Security Properties
The easiest way to take ownership of a file or folder is from the properties of the folder or file.
Here are the steps:
- Right-click the folder. Then click Properties.
- At the folder Properties, click the Security tab.
- Then click Advanced.
- When the Advanced properties of the folder opens, beside the current owner, click Change.
- At Select User or Group screen, type the user name of the new owner. Then click Check Names.
- If Windows finds the name on the PC, it will resolve it. Click OK.
- Back at Advanced properties of the folder, the new owner will now be listed beside Owner. If you wish to change ownership for sub-folders in the folder check Replace owner on subcontainers and objects. Then click OK
- Finally, at the properties of the folder, click OK.
Take Ownership of Folder in Windows 10 with Command Prompt
Another method to take ownership of folder in Windows 10 is with command prompt.
Here are the steps:
- Open Command Prompt as Administrator (Link opens in a new browser tab)
- To grant ownership of the folder “D:\MountedImages” to the logged in user, type this command. Then press enter.
TAKEOWN /F D:\MountedImages
- To gives ownership of a folder to the Administrators group instead of the current user, use the command below.
TAKEOWN /F D:\MountedImages /A
- Finally, to change ownership for the folder and all sub-folders, include the /R switch.
TAKEOWN /F D:\MountedImages /A /R
The command will scroll through, modifying the ownership of all sub-folders. If it gets to a folder you do not have permission to access, it will request to grant you full control. To continue, type Y.
Conclusion
These are the 2 common methods to take ownership of a folder. You can also use PowerShell. This guide covers the details of how to use PowerShell to take ownership of a folder – Changing Ownership of File or Folder Using PowerShell.
I hope you found this guide helpful. If you did, please spare two minutes of your time to share your experience with our community at [discourse_topic_url].
In addition to that, if you have any questions or want to share the method you used, you can also post them at [discourse_topic_url]. Our community forum staff and other community members are always ready to find answers to questions raised by our readers.
Lastly, for more Windows 10 guides, visit our Windows 10 How-To page.
That PS-Script is frakked up cause of the ” after the @
you cant use that,full of errors
How could this command be run in PowerShell? I am trying to do this exact command in script format for a shared folder. I would like to set the folder permissions above as you have mentioned to domain admins
$AdjustTokenPrivileges = @”
using System;
using System.Runtime.InteropServices;
public class TokenManipulator
{
[DllImport(“advapi32.dll”, ExactSpelling = true, SetLastError = true)]
internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall,
ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen);
[DllImport(“kernel32.dll”, ExactSpelling = true)]
internal static extern IntPtr GetCurrentProcess();
[DllImport(“advapi32.dll”, ExactSpelling = true, SetLastError = true)]
internal static extern bool OpenProcessToken(IntPtr h, int acc, ref IntPtr
phtok);
[DllImport(“advapi32.dll”, SetLastError = true)]
internal static extern bool LookupPrivilegeValue(string host, string name,
ref long pluid);
[StructLayout(LayoutKind.Sequential, Pack = 1)]
internal struct TokPriv1Luid
{
public int Count;
public long Luid;
public int Attr;
}
internal const int SE_PRIVILEGE_DISABLED = 0x00000000;
internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
internal const int TOKEN_QUERY = 0x00000008;
internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
public static bool AddPrivilege(string privilege)
{
try
{
bool retVal;
TokPriv1Luid tp;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
retVal = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
retVal = LookupPrivilegeValue(null, privilege, ref tp.Luid);
retVal = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
return retVal;
}
catch (Exception ex)
{
throw ex;
}
}
public static bool RemovePrivilege(string privilege)
{
try
{
bool retVal;
TokPriv1Luid tp;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
retVal = OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok);
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_DISABLED;
retVal = LookupPrivilegeValue(null, privilege, ref tp.Luid);
retVal = AdjustTokenPrivileges(htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero);
return retVal;
}
catch (Exception ex)
{
throw ex;
}
}
}
“@
add-type $AdjustTokenPrivileges
$Folder = Get-Item “\\igo-nas-2021\Scans\%username%”
[void][TokenManipulator]::AddPrivilege(“SeRestorePrivilege”)
[void][TokenManipulator]::AddPrivilege(“SeBackupPrivilege”)
[void][TokenManipulator]::AddPrivilege(“SeTakeOwnershipPrivilege”)
$NewOwnerACL = New-Object System.Security.AccessControl.DirectorySecurity
$Admin = New-Object System.Security.Principal.NTAccount(“BUILTIN\Administrators”)
$Folder.SetAccessControl($NewOwnerACL)
$NewOwnerACL.SetOwner($Admin)