Taking ownership of files in Windows is necessary to edit or delete system or program files that you have no access to by default. There are multiple ways to achieve that goal, like doing everything manually through the Properties menu, applying a registry tweak or, as described here, executing a command in the Command Prompt. Note that taking ownership will not let you edit every system file. Windows has set precautions so that you don't edit any of the most important files which may be helpful in some cases but can be really, really annoying in other.

To start off, you need an elevated command prompt which is simply a command prompt opened as administrator. In Windows 8 you can open that by right-clicking the bottom left corner of the screen and selecting Command Prompt (Admin). In Windows 7 and previous, search the main menu for cmd, right-click it and select Open as administrator.

You need two commands now: one to actually take ownership of the file or folder and one to grant yourself access rights. These are the two commands you will want to use:

For folders, use:

takeown /f folder_name /r /d y
icacls folder_name /grant username_or_usergroup:F /t /q

For files, use:

takeown /f file_name /d y
icacls file_name /grant username_or_usergroup:F /q

The commands basically only differ in a few switches that make the folder procession run recursively. If you want to edit only one folder instead of the whole recursive lot, remove the /r and /t switches from the commands. For more info on the commands, simply enter takeown /? or icacls /? into the command prompt.

If I wanted to take control of my Program Files folder, I'd need to enter the following:

takeown /f "C:\Program Files" /r /d y
icacls "C:\Program Files" /grant christian:F /t /q

Facebooktwittergoogle_plusredditlinkedinmail
Tagged on:                                     

18 thoughts on “Take Ownership of a File or Folder by Command in Windows

  • July 7, 2013 at 10:02 am
    Permalink

    So, hypothetically, if I used the TAKEOWN recursively on my Program Files that could open the door to malware down the line. How would I undo or restore such a change? Hypothetically of course.

    Reply
  • January 8, 2014 at 9:40 am
    Permalink

    Thanks a lot made my life easier

    Reply
  • March 2, 2014 at 12:17 pm
    Permalink

    A very useful post!
    Tried it out immediately.
    However note:
    Windows will not accept the /d option with file use.

    Reply
  • March 7, 2014 at 2:48 pm
    Permalink

    takeown /f folder_name /r /d y
    icacls folder_name /grant username_or_usergroup:F /t /q

    the above code is not working. please tell me another option to change the ownership.

    Reply
  • March 28, 2014 at 1:12 am
    Permalink

    @RVJ :
    I believe takeown is not available in Windows XP. What OS are you running ?
    What error mesage are you getting ans on which command ? Did you try tio run as admin in a dos command ?

    Reply
  • May 11, 2014 at 3:10 pm
    Permalink

    Very nice thanks. This has been blocking me for weeks.

    Reply
  • June 16, 2014 at 6:26 am
    Permalink

    Strangely these commands do not work on a folder that I have no access to … Windows 7 Professional.
    In both cases I got “Access is denied.”

    Any other techniques?

    Reply
  • June 19, 2014 at 8:19 pm
    Permalink

    Very useful, thanks. No longer need tools like unlocker, tools etc. Great for removing old installations of Windows etc.

    Reply
  • August 19, 2014 at 10:49 am
    Permalink

    thank you very much, helped me a lot

    Reply
  • November 6, 2014 at 6:56 am
    Permalink

    Aweso,e………….workede like hell ‘

    Reply
  • January 2, 2015 at 7:11 pm
    Permalink

    THANK YOU SO MUCH! It is rare to find concise and clear explanations of this kind of process and I can’t say how happy I am that this solution was so simple.

    Reply
  • January 7, 2015 at 5:32 pm
    Permalink

    Thanks a million for posting. I’m new to Windows 8 and was trying to clean up some of the old files it leaves behind after a “clean” install. I had loads of folders to clear and it was going to be a real chore to right-click and set properties that many times. The files were rightfully mine, but Win8 just didn’t know it. This solution was a million times easier than any other I found. For whatever reason even being a member of ‘Administrators’ was not allowing me to delete the files I wanted gone.

    Really appreciated, OP.

    Reply
  • February 27, 2016 at 10:38 pm
    Permalink

    I just did this:
    takeown /f C: /r /d y
    This is taking forever! lol
    I wonder why it has to print everything.. I wanted it to be faster so instead of printing every file just print the file that you fail to take ownership..
    Or on every entry print a single green dot (for success) and a red dot (for failure) and at the end of that operation ask if I want to know which file fails and print them all
    Microsoft come on… stupid…..

    Reply
  • February 27, 2016 at 11:17 pm
    Permalink

    I was pulling my hair. Somehow when I installed a software and failed to complete because of an error, there were folders, sub folders and files left behind that had security permission issues and the installer refused to install again due to those locked folders, sub folders and files. I can chnage the permission on file at a time but that was terrible solution. It was going to take me several days doing it. I was at the end of the rope when I found this page. It really works. I was able to get rid of all those folders, sub folders and files by taking ownership of the main folder then deleted in one shot.

    Thank you a very much.

    Reply
  • February 29, 2016 at 11:00 am
    Permalink

    (icacls file_name /grant username_or_usergroup:F /q) comes back as successful, but when i enter dir /q the file ownership hasn’t changed. (Takeown /f file_name) works but it’s not very comfortable because i’d have to log in as the user that i want to grant the file ownership to make this work.

    Reply
  • February 29, 2016 at 2:11 pm
    Permalink

    Won’t work with Program Files folders in Win 10… Does ANYBODY have an idea how to take ownership there?

    Reply
  • May 21, 2016 at 6:45 am
    Permalink

    could the commands be please clarified with respect to folders/files Drives etc

    Reply
  • May 21, 2016 at 8:37 am
    Permalink

    takeown /f folder_name /r /d y
    icacls folder_name /grant username_or_usergroup:F /t /q

    Q: Is it that each folder name has to be mentioned one by one?What if I want to apply a single command to all the folders rather than each folder separately
    Also, what are the letters r/d y and F/t/q denote?Are these the letters indicating the drives or what are these?
    For files, use:

    takeown /f file_name /d y
    icacls file_name /grant username_or_usergroup:F /q

    Similarly do I have to apply file names one by one ,isn’t there any command which can be applied to all the folders/subfolders/files/start up Icons which often change, show empty or just disappear whenever reboot is done or new program is installed and I have to restore all one by one through right click>properties>security>permission>ownership

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *