How To “Take Ownership” Of A File Or A Folder And Add It To Right-Click Context Menu Of Windows File Explorer

At some point in time you may come across a file or a folder that Windows denies you access to, even though your account belongs to the Administrator group. If this is the case, you would want to see if taking ownership of that file or folder can help you. In this article I’ll first describe how to do so “the regular way” and then explain how to simplify this process by adding a context menu item in File Explorer so you would be able to take ownership with two clicks of a mouse.

Let’s start with the regular way. As an example, let’s say you are unable to access the C:\temp folder (the same process can be applied to a file). First, right-click on the folder, select Properties and then switch to the Security tab:

Security tab in folder properties

Security tab in folder properties

Click on the Advanced button and select the Owner tab in the Advanced Security Settings window that pops up:

Advanced Security Settings tab

Advanced Security Settings tab

Click on the Edit button and then on Other users or groups button in the newly opened window. When the Select User, Computer, Service Account, or Group window opens, type in your login name in the text box and click Check Names to verify you are all set:

Select User, Computer, Service Account, or Group dialog

Select User, Computer, Service Account, or Group dialog

That’s it! You are now the owner of the C:\temp folder.

Now let’s get to the fun part of this article – with everyone automating tasks to be time efficient, wouldn’t it be cool if you could take ownership of that folder or file with two clicks?

In order to do so, we will do some Windows registry magic. First, fire up Windows Registry Editor, either by clicking Start > Run and entering regedit in Windows XP, or entering regedit in the Search programs and files box in Windows 7. Once there, navigate to HKEY_CLASSES_ROOT\*\shell in the left pane:

Browse to HKEY_CLASSES_ROOT\*\shell in Windows Registry Editor

Browse to HKEY_CLASSES_ROOT\*\shell in Windows Registry Editor

Go ahead, right-click on the white space in the right pane and select New > Key – name it runas. You will see a (Default) REG_SZ value created automatically – double-click on that and give it a value of Take Ownership – this is what will show in the menu in File Explorer:

Change the dafeult value to "Take Ownership"

Change the dafeult value to "Take Ownership"

Create a new string value by right-clicking on the white space, name it NoWorkingDirectory and leave the value blank:

Add a string NoWorkingDirectory value

Add a string NoWorkingDirectory value

Finally, we need the command that will grant you the ownership of the file or folder. The command prompt takeown command can help us in taking control over the file or folder that is denied access to. Given how this is a built-in command, we’ll need to use cmd.exe /c in order to execute that when you click on the context menu item. I am not going to go into details about what particular parameters mean – if you are interested in what they mean and what else you can do, visit Microsoft page on Takeown command. So, let’s define the command we would like to run when the Take Ownership item is clicked. Create another key under runas and name it command. Double-click on the (Default) and change the value to cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F. Now, create a String Value, name it IsolatedCommand and give it the same value (cmd.exe /c takeown /f \"%1\" && icacls \"%1\" /grant administrators:F). You should have the following at the end:

Define the command to take ownership of a file or a folder

Define the command to take ownership of a file or a folder

While you are already good, you would probably want to make this accessible in the context menu that shows when you are in a folder and right-click on the white space in the right pane. All you need to do now is to go ahead and repeat the above for the HKEY_CLASSES_ROOT\Directory\shell key in the registry. You can now take ownership by simply right-clicking on a file or folder and then selecting Take Ownership from the context menu:

Take Ownership of that file or folder from context menu!

Take Ownership of that file or folder from context menu!

This entry was posted in Windows and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

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