In earlier versions of Windows there were no command-line tools to take ownership of files or folders. You needed to use the Security tab in the file or folder properties to change the ownership of an item. Windows 7 and Windows Vista include a command-line tool named Takeown.exe that can be used from an admin Command Prompt to change the ownership of a file system object easily.

Taking ownership of a file

Open an elevated Command Prompt window. To do so, click Start, click All Programs, click Accessories, right-click Command Prompt, and then click Run as Administrator.

Type the following command and press ENTER:

TAKEOWN /F <filename>

(Replace the text <filename> with the full path of the actual file.)

If the operation was successful, you should see the following message:

"SUCCESS: The file (or folder): "filename" now owned by user "Computer Name\User name"."

Then to assign the Administrators group Full Control Permissions for the file, you may use the ICACLS command. Use this syntax:

ICACLS <filename> /grant administrators:F

Taking ownership of a folder

Use the following syntax:

takeown /f <foldername> /r /d y

Then to assign the Administrators group Full Control Permissions for the folder, use this syntax:

icacls <foldername> /grant administrators:F /T

The /T parameter is added so that the operation is carried out through all the sub-directories and files within that folder.

Command-line help: To know more information about the above commands, run these commands from a Command Prompt window.

takeown /?

icacls /?

Customizations

#1 Command Script

To further simplify the process of taking ownership, Tim Sneath of Microsoft provides a .CMD file (Windows Command Script) which takes ownership and assigns Full Control Permissions to Administrators for the directory which is passed as a parameter to the CMD file. For more information, read Tim’s post Windows Vista Secret #11: Deleting the Undeletable.

#2 Add "Take Ownership" command to the Context menu

This again uses the special runas verb in Windows 7/Vista, which has been covered many times in this Website (REF runas).

via WinMatrix.com

Download takeown_context.reg and save to Desktop. Right-click on the file and choose Merge. Click Yes when asked for confirmation.

This adds an extended command named Take Ownership in the context menu for files and directories. To access the command, you need to press and hold the SHIFT key down, and then right-click on a file or folder.

Sample Scenario: Let’s assume that you’re trying to delete a folder for which you don’t have permissions (although you’re logged in as Administrator) and getting an Access Denied error:

Simply press and hold the SHIFT key down, and right-click on the folder that you want to delete. Click the Take Ownership command.

You should now be able to delete that folder!

Bookmark this Page!

BlinkList | del.icio.us | Digg it | Furl | reddit | Spurl | StumbleUpon |

Related Posts


Email SubscriptionPrefer an E-mail subscription?

Enter your email address:

Delivered by FeedBurner

7 Responses to “How to Take Ownership of a File or Folder Using Command-Line in Windows 7 and Vista” Subscribe to comments!

  1. g
    said this on Tuesday, September 22nd 2009 11:06 am

    Sure no one makes a tool for this purpose?

  2. said this on Monday, April 13th 2009 12:57 am

    very helpful… Thanks!

  3. said this on Wednesday, March 11th 2009 5:45 pm

    Thanks so much this has just made me so happy – my biggest frustration with win7/vista solved!!!!!!!!!!!!!!

  4. per
    said this on Thursday, February 19th 2009 10:40 pm

    big thanks. it works w/ my windows 7 beta!

  5. mdhilliard
    said this on Saturday, February 7th 2009 10:40 pm

    Thank you! This appears to have solved a poblem regarding the hijacking of my default search provider.

  6. Tyler Bissonnette
    said this on Wednesday, November 26th 2008 2:08 am

    THANK YOU, that to me was the biggest problem with vista and now it’s solved. Once again cannot thank you enough.

  7. Andrew Leonard
    said this on Monday, November 3rd 2008 1:11 am

    That was possibly the best post I have ever seen anywhere. Thank you so much. After a mobo failure I had to get data off old hard drives onto new one. It seemed as though I had to use vista to get permission for every file in every directory and subdirectory – and then I read this post and had the whole lot done in under five minutes.

    Genius!

Leave a Reply