How to Change file or folder owner on Windows 7?
This morning I tried to update source of one of open source libraries for one of my applications. The source is hosted
under subversion. Since I had upgraded my machine from Windows XP to Windows 7 so I had
to reinstall TortoiseSVN tool. The tool installed fine without any issues and shell extensions installed
nicely as well. And I got the ability to right click on the code folder and click on SVN Update. So far so
good. The update dialog box comes up and after few seconds I get the error message
read-write: Access is denied
I realized that I am not using Windows XP anymore. And I am dealing with Windows 7 UAC now. Why did I get
the error? Here are the reasons:
- The folder was created when I was using Windows XP. Although I have not changed my login name on the machine
but I have a new SID now. So I am not the folder any more. See the following two snapshots. First one shows
who the current owner is and second one shows that owner's SID is unknown, indicated by a ref ?
on left side of SID.
Even though I am logged in with administrator account, I am not technically administrator. I am just a Protected Administrator (PA).
If you are upgrading from Windows XP then you are already familiar with User Access Control (UAC) technology and
all the restrictions introduced with it. On Windows XP, an administrator account had previleges on all folders in the
system. But on Windows 7, protected administrator account can not do that.
If you look at the permission set for the standard users account on the machine, you will notice that it does not have
Write permissions on the folder. You can see it in the following snapshot.
For an application to update these files, you will have to do one of the following things:
- Your application should be running under the credentials of the file owner. Since that SID is invalid now, that is not
an option any more.
- Get your application to "Run as administrator" or relax UAC. This is something that can be done as last resort if all else fails.
- Change ownership of the file or folder to new user account. This is the option I like the most because
I am not compromising UAC settings and I am doing the correct thing of changing ownership to valid account. This
is what I am going to explain in next section.
How to change file ownership in Windows 7?
These are some very straight forward steps with slight caveat here and there. Of course there are going to be some
caveats, its Windows. Here are the steps that will describe how to change owner of an existing file, especially
when existing file owner account is not valid any more.
Right click on folder or file in Windows Explorer and select Properties menu option. This will bring
up Properties dialog box for that file or folder.
- Select Security Tab. It will bring up view as shown below and click on Advanced button
- Now you will have Advanced Security Settings dialog box. In this dialog box, select Owner
tab at the top and it will bring up view as shown below.
- Now you will have Owner dialog box as shown below. In this view, select the user account that needs to be
assigned new owner of the file or folder. If this is a folder, then you can select Replace owner on subcontainers and objects
if you want the owner change to propagate to all child nodes under this folder as well. And then click on Apply
button for change to take into effect. If you have lot of subfolders or hierarchy is too deep, then it may take few seconds to
minutes for changes to apply.
Now your application should be able to make changes to files if it is running under your account.