Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Every so often I run into a file that I need to take ownership of. I normally use cacls for changing ntfs permissions, but it doesn't seem to do ownership. Under *nix I would run something like chown me:me <file>. Is there a windows equivalent to chown?

share|improve this question
    
too bad setACL isn't working with the script above. errormessages on Win XP, 7 and 8 and you need to be a proffesor to find what's wrong with it –  user176031 May 31 '13 at 12:40
add comment

10 Answers

up vote 17 down vote accepted

subinacl is a Windows sysadmin's power tool for doing everything to do with ownership and ACLs. You can change the ownership to anyone other than just you (you can't do this with the GUI).

subinacl /file test.txt /setowner=domain\foo

This lets you set the permission to any user you like, without having to be an administrator (as I believe takeown.exe requires).

share|improve this answer
    
Forgot about subinacl. Thanks! –  Joe Jun 17 '09 at 16:00
add comment

You're looking for "TAKEOWN.EXE", which was first in Windows Server 2003 as a standard component, and I believe a resource-kit item prior.

See: http://technet.microsoft.com/en-us/library/cc738152(WS.10).aspx

share|improve this answer
add comment

You might want to take a look at SetACL, the swiss army knife of permission management. Here is an example of how to assign ownership of all files on drive C: to "Administrators" and remove protection of inheritance from all child objects in one go:

SetACL.exe -on "C:\" -ot file -actn setprot
           -op "dacl:np;sacl:nc"
           -rec cont_obj
           -actn setowner -ownr "n:S-1-5-32-544;s:y"
share|improve this answer
add comment

For Windows 2003, 2008 or Vista or 7 use Takeown.

For Windows 2000 use Fileowners.pl.

share|improve this answer
1  
And for Windows XP, panic... smile –  Evan Anderson Jun 17 '09 at 15:16
    
Whoops, fixed! :) –  Dave Drager Jun 17 '09 at 16:09
add comment

In Windows Server 2003 R2 (and later) you can take advantage of the built-in tool icacls.exe to change ownership from the command line, as well as all of the traditional cacls.exe manipulations upon which it expands...

Note that icacls.exe defaults to "edit" mode, while cacls.exe defaults to "replace" mode--a welcome change to those of us bitten (more than once) by that little nuance of cacls!

share|improve this answer
add comment

Take ownership and full rights of folder and everything inside:

takeown /F somedir /A /R
icalcs somedir /grant:r User:F /T

I had to start a command prompt as administrator, but it worked for me in Windows 8.1. With Windows 8.1 awkwardness, I had to search for "command", right click on the command prompt icon, in order to see the "run as Administrator" option. I had a command prompt pinned to my taskbar, but right clicking on it would not show the "run as Administrator" option.

share|improve this answer
add comment

Another alternative is fileacl It is small and can set/unset "inherit/don't inherit" flag on the object, unlike most windows utils.

share|improve this answer
add comment

I've found a solution using Windows Tools: cacls

cacls <file or directory> /E /T /G <user>:F
share|improve this answer
add comment
  1. open command prompt as admin user and change to problematic directory
  2. take ownership of all files there ... example: takeown /f *.jpg
  3. grant access rights to users of your choice ... example: icacls *.jpg /grant "Everyone":F
share|improve this answer
add comment

I know this is a really old post, but there is a way built into Windows 7 and newer (may be in Windows Vista, but I am not sure). Run the following from an escalated command prompt in the folder that you want reset. /t tells icacls to perform the operation recursively.

icacls .\* /setowner %UserDomain%\%UserName% /t
icacls .\* /reset /t

The first command resets the owner to who ever is logged on via the environment variables. Of course, a specific name can be used instead.

The second command then forces the permissions to be reinherited down the tree to all of the child folders and files.

Hope this helps someone in the future.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.