Windows is saying access denied to files I own

15,887

Solution 1

Use the takeown command from a administrative command line. It is possible to remove Full Access permissions to the Administrators group, if that happens the GUI version can't change permissions but the command-line command can still do it.

takeown /f C:\dev\nvg510controls\.git /r /d Y

if you want to be extra fancy you can set the permissions via the command line too

icacls C:\dev\nvg510controls\.git /t /grant Everyone:(F)

If neither of those commands work download PsExec and do the command

psexec -i -s icacls C:\dev\nvg510controls\.git /t /grant Everyone:(F) 

that will run icacls as the SYSTEM user instead of the Administrator user.

Solution 2

I don't know if that's going to help anyone out but I'll note here that I've just had a problem with Git not having permission to access files and tried the answer above with no success.

The problem turned out to be that, on a fairly new server, an enterprise virus checker saw a lot of activity in the .git directory from the Git process, marked Git as a suspicious process and stopped allowing it to access any files.

Share:
15,887

Related videos on Youtube

The_g U r U
Author by

The_g U r U

Hello there! My name's Jordan Earls, but most people online know me as "earlz". I'm the lead developer and a co-founder of the Qtum project which brings the Ethereum Virtual Machine (ie, the thing that makes Solidity contracts function) to a UTXO based blockchain similar to Bitcoin. I've been programming since I was 13 and am completely self-taught. Low-level code like assembly and pointer arithmetic is the fun stuff for me. I also make music when I have time even though it's usually awful. Most of my personal projects are open source and BSD licensed. The majority of them are at bitbucket with the rest of them being listed on github Also, you can follow me on the twitters @earlzdotnet

Updated on September 18, 2022

Comments

  • The_g U r U
    The_g U r U over 1 year

    So, recently Windows has decided to do some trolling on me and make it impossible to commit to my git repository

    It gives me this error in git (in Cygwin):

    $ git commit -a
    error: insufficient permission for adding an object to repository database .git/objects
    
    error: NVG510Fixer/NVG510Fixer/Resources/layout/WarningConfirmation.axml: failed to insert into database
    error: unable to index file NVG510Fixer/NVG510Fixer/Resources/layout/WarningConfirmation.axml
    fatal: updating files failed
    

    Well... but then I go to the NVG510Fixer folder and recursively take ownership of everything in there and make sure that Everyone has full control. This seems to work, but it doesn't make the error go away.. So, I decide to go to .git and right click on properties and take ownership(recursively) from there. At this point, it gets even more weird:

    enter image description here

    What the hell is Windows doing?! I'm an Administrator. This computer isn't even joined to a domain. How can I not access files that I could access just a few minutes ago!?

  • Ramhound
    Ramhound almost 11 years
    This likely should have been a comment since you didn't explain HOW to change the owner to another user.
  • John
    John almost 10 years
    Tried this for a similar situation and "Error:Access is denied"
  • Scott Chamberlain
    Scott Chamberlain almost 10 years
    @John then you where not running it from a administrative command line. You need to make sure you choose "Run As Administrator" when you opened the command prompt.
  • Jason Southwell
    Jason Southwell over 7 years
    I get Access is denied as well, and I'm definitely in an administrator command prompt.
  • Scott Chamberlain
    Scott Chamberlain over 7 years
    @JasonSouthwell In that situation it is likely that the file is protected in a way that only the SYSTEM user can modify it. In that situation use PsExec and do the command psexec -i -s icacls C:\dev\nvg510controls\.git /t /grant Everyone:(F) that will run icacls as the SYSTEM user.
  • Jason Southwell
    Jason Southwell over 7 years
    I had tried that and saw nothing. I did figure it out though. in my case, it was that the folder was still open in a Windows 10 Anniversary Edition bash shell somewhere on my desktop. Apparently when git tried to remove the folder, it was still open there and put the folder in some limbo state. cd'ing out of the folder in bash automatically made the folder disappear. Odd I didn't see bash as holding a lock on that folder though.