Dave's Computer Tips is your FREE how-to, tips, tricks, and news source for computers, mobile devices, and technology!

How to take ownership of a file in Windows 7 and Vista

By default Windows 7 and Vista protect files and folders that it believes are important to the operating system. These files are even protected from users operating under administrative permissions. The reasoning behind this is two fold; first so the user doesn’t delete an important file which can render Windows unusable, and second to prevent spyware or a virus from interacting with system files.

Sounds all well and good, doesn’t it? The problem is occasionally Windows or another program will not release it’s hooks from a file after it is done using it. There are also instances where you really do want to change or replace a system file. Each of these situations will result in a “no go” from Vista or Windows 7. No delete, no change, no rename. Just a “you can’t do that” and an offer to try again!

Defrag.exe as an example

Let’s have a look at the windows defrag program. You can follow along by navigating to c:windowssystem32defrag.exe. Right click on defrag.exe and select properties. In the window that opens click on the Security tab and you will see the following:

This tab allows you to see and edit security permissions for a file. With Administrator highlighted you can see that Windows restricts the actions to “Read” or “Read & Execute”, even for the computer Administrator. This means no one using this computer can rename, change, delete, or otherwise alter the file. Click on a few other choices in the upper window and see what the differences are. (It’s OK, I’ll wait…)

What you will find that only TrustedInstaller (part of the operating system) has full privileges.

Taking ownership of a file

All is not lost! There are actually three separate ways you can go about correcting the issue and I’ll show you two of them.

Taking ownership the old fashioned way – using the command prompt

Click the Start Orb and type cmd. This will produce “cmd.exe” as the result in the top of the window. Right click on “cmd.exe” and select Run as Administrator.

You will receive a UAC (User Account Control) warning, which you should approve.

Doing that correctly will open the window below (called the command prompt).

This is a command prompt with elevated privileges. (notice the word Administrator in the upper left), which will allow you to do things you could otherwise not do from a command prompt. You have told Windows that you want to have complete control and Windows displayed the UAC warning to double check your decision.

The first command to type at the command prompt is takeown /f filepath (takeown

/f
filepath). Substitute filepath with the complete path to the file you wish to take ownership of. Using defrag.exe as an example the command would be takeown /f c:windowssystem32defrag.exe

If you entered the command and filepath correctly when you press the enter key the command will be carried out and you will receive the following message indicating success.

The second command is icacls filepath /grant yourusername:f (icacls

filepath
/grant
yourusername:f). Substitute filepath with the complete path to the file you wish to take ownership of. Substitute yourusername with the username you logged onto your computer with. Also notice there is no space between the username and “:f”.

Continuing with defrag.exe as an example I would type icacls c:windowssystem32defrag.exe /grant David:f.

If you entered the command and filepath correctly when you press the enter key the command will be carried out and you will receive the following message indicating success.

Just for grins go back and check the properties of the file you took ownership of.

You can see that I have ownership of the file! This may seem a little complicated, or difficult. How about an easier method?

Taking ownership of a file the easy way – editing the registry

I promised easy and then tell you editing the registry is required. What am I thinking? :)

OK, where is the easy way. Open notepad (Start>Accessories>Notepad), highlight and copy the text between the lines below, paste into Notepad.

————————————————————–

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT*shellrunas]
@=”Take Ownership”
“NoWorkingDirectory”=””

[HKEY_CLASSES_ROOT*shellrunascommand]
@=”cmd.exe /c takeown /f ”%1” && icacls ”%1” /grant administrators:F”
“IsolatedCommand”=”cmd.exe /c takeown /f ”%1” && icacls ”%1” /grant administrators:F”

[HKEY_CLASSES_ROOTDirectoryshellrunas]
@=”Take Ownership”
“NoWorkingDirectory”=””

[HKEY_CLASSES_ROOTDirectoryshellrunascommand]
@=”cmd.exe /c takeown /f ”%1” /r /d y && icacls ”%1” /grant administrators:F /t”
“IsolatedCommand”=”cmd.exe /c takeown /f ”%1” /r /d y && icacls ”%1” /grant administrators:F /t”

————————————————————–

Your screen should look something like this:

Use File>Save As to save the file to your desktop. I suggest you choose a descriptive filename, such as “take_ownership”. Go the the desktop and change the file extension from “.txt” to “.reg”. This will allow you to automatically merge these instructions into the registry without having to manually edit the registry. I told you it was easy!

Double clicking the file will result in the following warning:

Clicking Yes will import the information directly into your registry, so you do not have to enter it manually. You will receive a confirmation which you can click Yes to.

That’s all well and good, you say, but what exactly does this thing do? Adding this to the registry adds an entry to the right click menu which allows you to take ownership with just a mouse click!

Let’s have a look at a protected file, after we have added this info to the registry.

There you have it! Oh, wait. There is more…

Added bonus! The super easy way!

I’ve created the registry files for you, which you can download and apply. Simply download the following files, change the extension from .txt to .reg, and double click to apply.

take_ownership – Adds Take Ownership function to the right click menu of protected files

remove_ownership – Removes the Take Ownership function

Cautions

  • Always backup your computer before changing system settings!
  • Always backup your registry before making edits or merging files.
  • Use Take Ownership responsibly. This is an important security feature in Vista and Windows 7. As such, it should only be used when there is a need.
Share
About the author - David Hartsock
Executive Editor/Owner/Admin of Daves Computer Tips and all-around good guy - Dave's interest in computers began in the early 1980's during the Apple II era. In the early 1990's the PC began to replace proprietary and mainframe devices in Dave's industry so he began to learn and experiment with the PC. Through DOS, Windows 3.1, Windows 95, Windows 98, Windows 2000, Windows XP, Vista, and now Windows 7 Dave became the "go to" guy for friends, family, and coworkers with computer problems. Daves Computer Tips was born in 2006 in an effort to share these experiences with others in an easy to understand, plain English, form.
 
Comments

Thank you very much for this. the reg key addon works but it doenst work for exe files. is there away to have that menu show up for exe files or do i need to do it the old school way and change it using cmd

hye…for the cmd method, i already use the icacls commands, but the processing still failed…is there any way around?

If you typed the commands correctly the icacls method should’ve worked, but did you read the second part of the article? It explains, and in fact give the copy/paste text, how to do it by creating a text file and renaming it with the .reg extension?

Why not just do this, on the odd occasion that you need to, using the properties sheet? Roughly, it goes like this, give or take an OK or a YES:

Take a copy of e.g. Defrag.exe and put it somewhere safe, eg. C:\, just in case. Then right click on Defrag.exe, and select Properties, Security tab, Advanced, Owner, Edit, select yourself as owner (add yourself to Security Groups and Users if you aren’t already there, using Edit). Now select Apply and answer OK and YES until you finally close properties. Then reopen it and choose Security tab, Edit, add yourself (e.g. Dave) to the security groups and users if necessary, and give yourself full access. Done; now you can for example delete Defrag.exe, with Windows just asking if you’re sure about this.

Just a few clicks, and no command line or registry hack uncertainties; something is amiss if you are changing permissions a lot. Also works on a folder of course, in which case all the files in the folder can take on the same permissions.

Now, just for kicks, you can take ownership of System32, delete all the files in it, and time how long your PC keeps going. [ONLY KIDDING! DON'T DO IT!]

JMW

i have three pc in different areas and use backup hard drives to keep in sync. I seem to lose permission to files in different systems.

i hoped gaining ownership to these files would resolve my problem and tryed downloading your reg update. it failed with error file is not a registry script. need binary reg file. Please advise if i did anything wrong.

Also i see one of my problems is the files in question didn’t copy permissions from the parent folder.

Thanks for your help

Bill

Leave a Reply