Windows File Access Denied

8

2

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)

!exampel

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?

Tom

Posted 2012-10-26T12:46:41.887

Reputation: 347

Can you check the effective permissions for your user on a directory you don't have access? – None – 2012-10-26T14:35:40.270

The problem occurs on specific files. Files that are somehow created through applications called by my .bat file (Does not help being an administrator account + starting the .bat file with "run as administrator.) I have just uploaded a screenshot showing the dialog I get when trying to edit security for a locked file. (Normally for all the other non-locked files, I am shown the normal security dialog. But with the locked, I get "access denied" to even edit security.) – Tom – 2012-10-26T15:50:05.410

1Can you check the permissions on your batch file? – None – 2012-10-26T17:20:34.763

Verified Users (Translated from Danish): Modify, Read&Execute + Read + Write. System + Admins: Full Control, Modify, Read&Execute + Read + Write. Users: Read + Read&Execute – Tom – 2012-10-26T17:44:31.277

1Files inherit the permissions of the parent folder when they are created, maybe check the permissions of the parent folder? – David – 2012-10-26T17:55:19.250

For all folders wherein files are created / bat file run from etc: Verified Users + System + Admins: Full Control, Modify, Read&Execute + Read + Write + ListFolderContent. Users Read + Read&Execute + ListFolderContent – Tom – 2012-10-26T18:03:00.610

You say you have problems when your BAT file creates/manipulates files.  What happens if you execute the same commands directly at the Command Prompt (i.e., copy from the BAT file and paste into Command Prompt)? – Scott – 2012-10-26T21:37:40.040

1I 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 – 2012-10-26T21:38:31.707

W: is a partition on a local disk (W = work). However, during my continued testing yesterday, I found the reason may be slightly different than what I first assumed. It appears the delete instructions given in the .bat file are delayed by minutes. (i.e. from the delete instruction is given, the delete is first done after e.g. 3-4-5 minutes. And meanwhile any operations on the file give access denied errors.) I have zero idea about what is going on since deleting files normally is instantaneous. And I have tried disabled AVG... So... No idea... :( Updated initial description/question at bottom – Tom – 2012-10-27T14:48:04.770

Just for reference, this is still a problem. After the delete instruction is given, it can sometimes take up to 10 minutes before the file actually is removed (if watching wih e.g. Windows Explorer), and until then all operations on the file are denied. (Beyond thad, there are also other slightly funky file access errors in my system. (I don't know if related or not. But if I download files to desktop using e.g. FireFox, I am told it does dot have access rights tto place the file there.) I suspect this whole thing may be associated to some Windows (security?) registry settings. – Tom – 2013-02-05T07:57:29.810

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 – 2013-02-05T10:06:26.837

Already tried buying and using a new disk. Problem persist :( (That said, I will of course ry run a disk check later today and report, just in case) – Tom – 2013-02-05T10:47:11.247

If you have multiple disks/partitions you might want to run it on all of them. – James P – 2013-02-05T11:49:14.447

1Which 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 – 2013-02-05T16:32:57.930

Can you post some syntax from your batch file so we know what is going on? – BroScience – 2013-02-05T21:43:14.600

@ScottChamberlain It is execuables (example.exe) but they are not running anywhere any longer (neither the program that created them, nor themselves) if e.g. checking Windows task manager. – Tom – 2013-02-06T10:25:16.977

@BroScience It is a simple: del "%V_Disk_Org_CompiledExeImmediate%" . As the original post states, the deletion does come through... If you wait like 5-10 minnutes. All subsequent actions on the file (while waiting for the "del" to come through) results in "access denied". – Tom – 2013-02-06T10:27:18.363

1@Tom: did you try the disk check? If that doesn't help I would suggest you try Safe Mode to determine if a program is responsible. – James P – 2013-02-08T21:56:25.420

@James No luck. (But it would also be odd since the disk is very new + the problem was also there on the old disk.) – Tom – 2013-02-11T01:00:03.373

@James I guess safe mode is worth trying. Will do. (Just ran chkdsk again and no problem reported of any kind on disk/partitions) – Tom – 2013-02-12T15:14:18.730

Answers

4

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.

Apple II

Posted 2012-10-26T12:46:41.887

Reputation: 3 669

I already tried a similar tool sugested elsewhere, but will try. – Tom – 2013-02-09T11:34:04.377

2

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.

itsWrongGuy

Posted 2012-10-26T12:46:41.887

Reputation: 86

If the parent folder prevents you from doing that do the same process with the parent folder and files within – itsWrongGuy – 2013-02-05T16:07:17.560

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 – 2013-02-06T10:22:04.613

2

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

Run chkdsk to fix it:

chkdsk /r C:

gronostaj

Posted 2012-10-26T12:46:41.887

Reputation: 33 047

Already tried, but no problems found – Tom – 2013-02-12T15:14:38.323

1

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.

Lelouch Lamperouge

Posted 2012-10-26T12:46:41.887

Reputation: 259

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 – 2013-02-11T01:02:34.417

BTW: I have also tried run the CMD with admin rights. no change. – Tom – 2013-02-13T14:00:00.177

0

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.

Tom

Posted 2012-10-26T12:46:41.887

Reputation: 347

-1

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.

Pierre de Grenoble

Posted 2012-10-26T12:46:41.887

Reputation: 11