Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access denied to file on windows 7 for Administrator account

I want to delete my git repository (.git folder) created by git on my windows 7 box. It says access denied to .git/refs/header folder.

I open a console with Administrator role, issue command "takeown /F heads /A /R", it still says "ERROR: Access is denied.", neither can i do via GUI security dialog.

Any suggestion?

Regards, Green

like image 416
Gelin Luo Avatar asked Dec 29 '10 03:12

Gelin Luo


People also ask

How do I fix access denied as administrator?

Folder Access Denied as AdminIdentify the folder and right-click on it. From the menu, tap “Properties” to open a new screen. Navigate to “Security,” then select the admin account. Check the “Permissions” section to ensure that all permissions have been granted.

Why is access denied when I am the administrator?

Check file/folder permissions Right-click the file/folder and select Properties from the context menu. Go to the Security tab. Select the administrator account from and check if it has permission in the Permissions section. If the account does not have permission, click Edit and grant it all permissions.


1 Answers

An access denied error may mean the file is in use by another process and, for a GIT repository, that seems more likely than a file permissions issue.

(I'm assuming GIT is like SVN where every file in the repository is created by your own account with standard permissions. If that's not the case then I may be wrong.)

  • As a first step, run Process Explorer as Administrator and push Ctrl-F to open a window where you can type the filename and see which processes (if any) have that file open.

    When I say "run as Administrator":

    I don't just mean when logged in as Administrator. Windows 7's UAC means Administrator accounts don't run things with full admin access by default. Right-click procmon.exe and choose the "Run as Administrator" option.

    I assume you're already familiar with this from running the command prompt as admin. If you just changed to an admin account, but didn't use "Run as Administrator" on the command prompt, then that could be why the takeown command failed. The command prompt should say "Administrator:" in its window title if it is properly elevated, unless UAC is off entirely.

  • If one or more processes are listed, confirm the full file path in the list (in case some other file on disk has a similar name).

  • Close any processes which have the file open. Try to close them normally if you can. As a last resort you can end-task them. If it's a process running as another user/account, it might be a service which you can stop.

    (Ensure View->Show Processes for All Users is ticked, then find the process in question via the PID column. If you think it's a service, hover the mouse over it and a tooltip will appear telling you the name(s) of any services it is running.)

  • If you cannot find any process accessing the file, or closing them all still results in an access denied error, and you are definitely trying the deletion from an elevated command prompt, then you might want to try telling Windows to delete the file the next time it is rebooted. You can use the SysInternals MoveFile tool for that.

like image 121
Leo Davidson Avatar answered Sep 21 '22 10:09

Leo Davidson