拒绝访问 Windows 7 上的管理员帐户文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4551229/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:55:58  来源:igfitidea点击:

Access denied to file on windows 7 for Administrator account

windowsgitwindows-7access-deniedadministrator

提问by Gelin Luo

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.

我想删除由 git 在我的 Windows 7 机器上创建的 git 存储库(.git 文件夹)。它说对 .git/refs/header 文件夹的访问被拒绝。

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.

我打开一个具有管理员角色的控制台,发出命令“takeown /F head /A /R”,它仍然显示“错误:访问被拒绝。”,我也不能通过 GUI 安全对话框来做。

Any suggestion?

有什么建议吗?

Regards, Green

问候,绿色

回答by Leo Davidson

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.

访问被拒绝错误可能意味着文件正被另一个进程使用,对于 GIT 存储库,这似乎比文件权限问题更有可能。

(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.)

(我假设 GIT 就像 SVN,其中存储库中的每个文件都是由您自己的具有标准权限的帐户创建的。如果不是这种情况,那么我可能是错的。)

  • As a first step, run Process Exploreras 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 MoveFiletool for that.

  • 作为第一步,以管理员身份运行Process Explorer并按 Ctrl-F 打开一个窗口,您可以在其中键入文件名并查看哪些进程(如果有)打开了该文件。

    当我说“以管理员身份运行”时:

    我不仅仅是指以管理员身份登录时。Windows 7 的 UAC 意味着默认情况下管理员帐户不会运行具有完全管理员访问权限的东西。右键单击 procmon.exe 并选择“以管理员身份运行”选项。

    我假设您通过以管理员身份运行命令提示符已经熟悉了这一点。如果您只是更改为管理员帐户,但没有在命令提示符下使用“以管理员身份运行”,那么这可能是 takeown 命令失败的原因。除非 UAC 完全关闭,否则命令提示符应在其窗口标题中显示“管理员:”(如果正确提升)。

  • 如果列出了一个或多个进程,请确认列表中的完整文件路径(以防磁盘上的其他文件具有相似名称)。

  • 关闭所有打开文件的进程。如果可以,请尝试正常关闭它们。作为最后的手段,您可以结束他们的任务。如果它是作为另一个用户/帐户运行的进程,则它可能是一个可以停止的服务。

    (确保勾选“查看”->“显示所有用户的进程”,然后通过 PID 列找到有问题的进程。如果您认为它是一项服务,请将鼠标悬停在它上面,将出现一个工具提示,告诉您任何进程的名称它正在运行的服务。)

  • 如果您找不到任何正在访问该文件的进程,或者将它们全部关闭仍会导致拒绝访问错误,并且您肯定是在尝试从提升的命令提示符中删除,那么您可能想尝试告诉 Windows 下次删除该文件它重新启动。为此,您可以使用 SysInternals MoveFile工具。