Unable to delete a file or take ownership on Win7x64

15

5

I'm a developer and as part of the build process, a Microsoft dll is copied to a certain folder. That file copy is now failing as the target can't be overwritten.

I decided to delete it by hand (using an admin account but a non-elevated explorer) so browsed to the folder and attempted a delete. This failed (Require permission from the Administrator). The same applies when using an elevated explorer.

So I tried Properties->Security->Advanced->Ownership

The current owner is showing as Unable to display current owner. I can't take ownership (a simple Access Denied message with no elaboration). Elevated Command Prompt/PowerShell don't help either (both give an Access Denied in their own way).

Process explorer shows no open handles on the file.

Eventually, I booted to linux and deleted the file but what I'd like to know is what caused it?

Security Essentials had no issues with the file. It's digitally signed by MS and the signatures match.

Basic

Posted 2012-10-16T13:56:13.850

Reputation: 945

I encountered the same problem. In my case I found the root cause -- when I wanted to delete the folder, my git Bash was open and its working directory was that folder. When I changed the git Bash's working directory, the folder was deleted successfully. – Hong – 2016-01-25T02:31:38.457

possible duplicate of File I can't take ownership of

– CharlieRB – 2012-10-16T14:12:44.767

@CharlieRB I've read it - but as you can see, my problem isn't removing the file but understanding what the "loss of ownership" is caused by. – Basic – 2012-10-16T14:23:19.413

You are right. Sorry. Guess I got lost in reading it and misunderstood the question. – CharlieRB – 2012-10-16T14:35:04.583

In some cases, deleting a file needs to be done externally, e.g. Safe Mode, or as you did booting into another OS. If the file has certain attributes (I'm not exactly sure but I think System affects it), along with the existing SYSTEM permissions, that makes it untouchable in the context of the booted Windows. Obviously once you go away from that context, it becomes irrelevant, but inside Windows 7 (and 8) some files are certainly undeletable. – None – 2012-10-16T16:05:27.793

@RandolphWest Thanks for the answer. Can you explain a little more? I know anything with an open handle can't be modified but suspect that if I deleted everything I could in my windows dir then rebooted, I'd have bricked my machine - so there's no "required for windows" flag set on a lot of files. Pagefile/etc come under the heading of open handles. I just don't see how a DLL buried in a folder on my D drive which has been replaced every few hours for days can suddenly be flagged as undeletable (nor what that "flag" is?) – Basic – 2012-10-16T16:39:28.950

It's not about open handles. I suspect Microsoft has an undocumented protection on certain files. If you can elevate to SYSTEM user, you might be able to delete the file that way, but yes, it's probably to do with protecting the system integrity. I've not researched this at all - I just know certain files need to be removed in either Safe Mode, or from an external OS. – None – 2012-10-16T18:34:14.697

Answers

19

I had this issue too for a file I manage with SourceTree ( git client ). This file had no 'Owner'. I just noticed that closing down all application susceptible to use it, removed it magically. The other option was to remove the file in windows' safe-mode. I don't know why this happened though and I'm curious too as to why this happened.

DarkUrse

Posted 2012-10-16T13:56:13.850

Reputation: 366

2This happened to me too, which is what brought me to this question. A git checkout created a folder, then afterwards I couldn't do anything with it (and couldn't checkout anything else that would modify it!). Your comment helped me realise I had other git bash windows open; once I closed them all the folder magically deleted :) – Tim Malone – 2016-04-26T00:50:45.483

3

One solution works for me on Windows 7 :

Right click the hard disk drive, ==> Properties / Tools / Check now .... And then try to delete again, it should work.

Bruno

Posted 2012-10-16T13:56:13.850

Reputation: 39

Warning: You have to reboot and the reboot may take several hours. – User – 2016-12-08T20:53:44.277

Update: After several hours, it did fix the problem. – User – 2016-12-09T19:05:36.627

1

In my case it was a file I'd used Firefox to download. Couldn't display owner, change ownership or delete the file (though it was readable). Using lockhunter to delete the firefox lock on the file worked.

user528821

Posted 2012-10-16T13:56:13.850

Reputation: 11

1

I found that a folder with "Unable to display current owner" was locked as a library location (such as Music Library). I removed that as a Location and I could delete folder.

Mak

Posted 2012-10-16T13:56:13.850

Reputation: 11

That's one hell of a gotcha, I would never have thought of that. Thanks. It wasn't the issue here, but it will definitely help others in future with the same symptoms. – Basic – 2016-10-30T21:33:38.540

0

I had the same issue with some files in the windows directory, most likely caused by a virus.

running sfc /scannow fixed the problem for me

Dieter Casier

Posted 2012-10-16T13:56:13.850

Reputation: 1

1

"most likely caused by a virus" http://xkcd.com/1180/

– Basic – 2014-12-10T11:51:32.337

-1

Open command prompt with admin rights, then type:

net user administrator - this will display current settings.

Use net user administrator /active:yes to activate if needed.

This is the built-in administrator account for managing the system. It is usually not active.

snayob

Posted 2012-10-16T13:56:13.850

Reputation: 4 044

1Thanks for the tip but if it was owned by the local admin account, 1) wouldn't another admin be able to take ownership and 2) wouldn't the security dialog have identified the owner? It was my understanding that only the SYSTEM account had higher permissions than a user in the administrator group – Basic – 2012-10-16T14:27:27.770

1Your understanding is correct, @Basic. – None – 2012-10-16T16:06:22.847