Take Ownership of a File or Folder by Command in Windows

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


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

  1. 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.

  2. 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.

  3. @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 ?

  4. 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?

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

  6. 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.

  7. 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.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>