I seem to have a general problem with "access denied on Windows". It manifests itself every time if e.g:

  • My bat file calls a compiler creates a file on disk
  • My bat file renames a file
  • But I also have files downloaded (FireFox) to Windows desktop where Windows is giving me "access denied" if I try delete the file.
  • Tried disable AVG + make exception in AVG resident shield

(I have tried checking with Task Manager + Winternals process explorer that it is not process running still running that should cause the locks.)

  • Windows 7.
  • My user account is an administrator.
  • All files are created by same user account.

The problem is recent, but some things I first noticed yesterday (when I started calling .bat files again which I have used for many years)

I have tried:

  • Starting e.g. Windows Explorer with "run as administrator", but that makes no difference
  • right-click - properties - security and changes permissions/ownership (I also get "access denied" when trying this so this does not help)

Here is a ascreenshot if I try change security of a "locked" file. (The problem here is the locking occurs continously every time the file is created)


If I click onwards, it states I am not the owner? Instead I see this: "Unable to display current owner"

If I try to change ownership, I get "access denied" (don't have rights)

Which baffles me as I just created it. (Yes, through a .bat file calling executables that create the file. But all running under my administrator user account.)

I think this is some kind of weird issue of something somewhere holding file handles for some time after file has been attempted deleted by .bat file...

I have tried to walk away 5 minutes after the .bat file has issue the delete instruction. (Pausing .bat script) When returning (after minutes) the file is gone. (This took some time for me to notice since it was by accident I discovered this, but it seems I can repeat it)

So the reason for all the problems may be the file somehow is in a kind mysterious state where the file has been scheduled for deletion, but it just goes extremely slow? (And hence all other operations performed on the file also behaves very oddly.)

I have no idea why this is (have tried disabling e.g. AVG), but I guess it could explain the sudden problems?

  • 1
    Can you check the permissions on your batch file? – user127350 Oct 26 '12 at 17:20
  • 1
    Files inherit the permissions of the parent folder when they are created, maybe check the permissions of the parent folder? – David Oct 26 '12 at 17:55
  • 1
    I notice that your pathname begins with W:, i.e., it is on a network share. Do you get the same problems on the C: drive? Is there any possibility that the file server doesn’t fully recognize your credentials? This might happen if you are an ordinary user on the domain, and Administrator only on your local machine. – Scott Oct 26 '12 at 21:38
  • 1
    @Tom: I recommend running a disk check (right-click the volume in My Computer and choose Properties->Tools->Error-checking->Check now... as it sounds as though your file system could be corrupt. – James P Feb 5 '13 at 10:06
  • 1
    Which file are you trying to delete that it is hanging on, is it {YourAppName}.vshost.{YourAppExtension} (ex: SampleApp.vshost.exe) by any chance? – Scott Chamberlain Feb 5 '13 at 16:32

Use Unlocker to unlock those files and then try to do whatever you want. Unlocker does natively support deletion, renaming etc, too.

[Optional] I'd also like to suggest you to scan computer for threats using Norton Power Eraser (Its free, portable; it can work along with AVG, too) if you don't exactly know whats causing the problem.

| improve this answer | |
  • I already tried a similar tool sugested elsewhere, but will try. – Tom Feb 9 '13 at 11:34

From this security Tab, click Advanced, Click the Owner Change link, in the Enter the object name box type your name and click CHECK NAMES then click OK. This will reset the Authority permission to you.

| improve this answer | |
  • If the parent folder prevents you from doing that do the same process with the parent folder and files within – itsWrongGuy Feb 5 '13 at 16:07
  • I can't access/change anything (including that) when the file is first in that state. As described, I believe it is because the file is beind queued for deletion but then "hangs" in the system for a long time. – Tom Feb 6 '13 at 10:22

Maybe your file system is corrupted. (see quite similar thread)

Run chkdsk to fix it:

chkdsk /r C:
| improve this answer | |
  • Already tried, but no problems found – Tom Feb 12 '13 at 15:14

You might want to try checking the permissions for CMD. Also check your task scheduler in case there's anything unexpected going on.

Sachin Shekhar's idea of using Unlocker is good to see if there is any other processes that is concurrently using the file. The compiler may be having some sort of bug and "hogs" the file even after it has completed it's operations.

| improve this answer | |
  • There is nothing in task scheduler. (Which is what is so odd. And why I think it is internal in Windows file deletion scheduling that slows down. But hard to say.) I will fiddle with CMD/mode if it makes any change. – Tom Feb 11 '13 at 1:02
  • BTW: I have also tried run the CMD with admin rights. no change. – Tom Feb 13 '13 at 14:00

Windows 10 seems to drasicly have improved and solved the behavior. Files are no longer "locked" / "file access denied" for a very long time...

So changing o Windows 10 is kinda an answer as well. Since so many people contributed to the post, I wanted to share back my findings as well.

| improve this answer | |

Yeah, running CHKDSK /R C:\ (at the next boot) did the trick! Afterwards it sounds relevant that the file system ought to be corrupted if you cannot take ownership of a file or folder you would be authorized to. Especially if Windows cannot state who's the owner of such a file or folder. Permissions have been clearly corrupted in such case. Many thanks for the tip! Cheers from France.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.