曾经尝试删除文件并获得访问被拒绝错误(delete a file and get an Access is Denied error)?或者您可能正在尝试复制或移动文件或文件夹(file or folder),并且您收到一条消息,说明源文件可能正在使用中(the source file may be in use)?发生此类错误的原因有多种:您没有文件或文件夹(file or folder)的所有权,因此无法对其执行任何操作,或者操作系统(operating system)或其他程序当前正在使用它。
您通常可以通过查看您正在尝试做什么来确定您所涉及的情况。如果您收到Access is Denied或您当前没有权限访问此文件夹消息( You don’t currently have permission to access this folder message),那么您可能正在查看权限问题。如果您不是计算机上的管理员,您可能无法解决此问题,因此首先确保您可以访问管理员帐户(admin account)。
访问被拒绝错误
此特定错误通常由NTFS权限引起,但也可能由其他问题引起,例如损坏的用户配置文件(user profile)、文件加密或文件是否正在使用中。我们将在下一节讨论文件使用中的错误。
要获得对文件或文件夹(file or folder)的访问权限,您需要为您的帐户配置正确的权限。在开始做任何工作之前,您应该尝试单击将自动显示在Windows 7和Windows 8中的(Windows 8)继续(Continue)按钮。只要您是所有者,这将尝试授予您的用户帐户对该文件夹的权限。(user account)
如果您在单击Continue后收到(Continue)You has been denied permission to access this folder (You have been denied permission to access this folder )消息,这意味着您不是该文件夹的所有者,您必须先获得该文件夹的所有权,然后才能更改任何权限。
获取Windows中(Windows)文件和文件夹(Files and Folders)的所有权
不幸的是,获得所有权是一个过程,因此最好在尝试之前有足够的时间和耐心。(time and patience)首先,您需要右键单击文件或文件夹(file or folder),选择属性(Properties),然后转到安全(Security)选项卡。
如果您无权访问该文件夹,您将看到一条消息,说明您必须是管理员(Administrator)才能查看安全属性。继续并单击继续(Continue)。这将弹出另一个对话框,您可以在其中选择更改所有者。
在将所有者更改为(Change owner to)框中,选择您的用户帐户或管理员(account or Administrators)。我个人选择我自己的帐户,因为这是创建新文件夹/文件时Windows中的(Windows)默认行为。(default behavior)还要确保选中替换子容器和对象的所有者( Replace owner on subcontainers and objects )框。单击“确定(Click OK)”,您将收到另一条消息,说明您无权阅读内容,是否要替换权限并授予自己完全控制权(Full Control)。单击(Click)是(Yes)。
现在确保在任何剩余打开的窗口上单击“确定”,以便关闭所有对话框。此时(Don)不要尝试更改任何其他设置。您必须首先关闭所有打开的对话框并返回资源管理器屏幕(Explorer screen)。在那里,再次右键单击文件/文件夹并选择 Properties 并转到Security 选项卡(Security tab)。它现在应该看起来有点不同。
此时您可以访问文件/文件夹的内容,但最好完全重置权限。此时,您刚刚添加了自己,仅此而已。如果您想要应用默认的Windows权限,您可以按照接下来的几个步骤操作。单击(Click)高级(Advanced)按钮,然后单击更改权限(Change Permissions)。
单击(Click)删除按钮(Remove button)并删除当前列出的所有权限。此时,它应该只是您的用户帐户。一旦列表框为空,请继续并检查从该对象的父框包含可继承的权限。(Include inheritable permissions from this object’s parent)然后单击应用(Apply)按钮,而不是确定按钮。
您应该会看到列表框中出现了几个条目,其中一个是您的用户帐户(user account)。默认权限通常还包括SYSTEM 和 Administrators(SYSTEM and Administrators),因此最好以这种方式正确重置它们。如果文件夹有许多包含文件的子文件夹,您可以选中将所有子对象权限替换为此对象的可继承权限(Replace all child object permissions with inheritable permissions from this object)框。关闭(Close)所有对话框,您应该一切顺利!
正如我之前提到的,在某些情况下,拒绝访问(Access)可能是由其他问题引起的。损坏的用户配置文件(user profile)是我在域环境中看到的更多奇怪问题之一。您可以创建一个新的用户配置文件(user profile),然后尝试访问该文件或文件夹(file or folder)。
另一个问题是文件是否已加密。您可以随时尝试通过右键单击并选择 Properties 来(right-clicking and choosing Properties)检查文件是否已加密。然后单击常规(General)选项卡中的高级(Advanced)按钮并取消选中加密内容以保护数据(Encrypt contents to secure data)框。
如果其他人加密了文件/文件夹,您将无法访问它,直到您可以使用他们的用户帐户(user account)对其进行解密。最后一个问题,如果文件本身已损坏。在这种情况下,您将不得不搜索可以帮助修复损坏文件的软件,尽管这是一个非常罕见的问题原因。
文件正在使用(Use)或共享冲突错误(Violation Error)
请注意,获取访问(Access)被拒绝消息可能是由共享冲突引起的,因此如果上述方法不起作用,请尝试以下过程。
您可以从Microsoft下载并安装名为Process Explorer的免费程序。您可以使用它来找出哪些进程正在锁定文件。解压后右击可执行文件,选择以管理员身份(Administrator)运行(Run),即可运行程序。然后不要担心所有疯狂的颜色和条,只需转到顶部并单击Find然后Find Handle or DLL。
现在在框中输入相关文件的名称并输入搜索。您不必输入文件的全名;它的一部分也将在大多数情况下工作。
您应该取回当前锁定文件的进程列表。就我而言,Notepad.exe锁定了我的测试文档(test document)。现在选择框中的项目,然后关闭搜索框(search box)。您应该回到主进程资源管理器屏幕(process explorer screen)。在底部,应该突出显示一行,它应该是您在搜索框中(search box)选择的文件的路径。
右键单击该行并选择Close Handle。如果搜索框中(search box)有多个进程,您将不得不对每个进程重复相同的过程。此时,您应该可以随意删除或修改文件。当您收到以下类型的错误消息时,该程序非常有用:
- 无法删除文件:错误 5(Error 5) 访问(Access)被拒绝
- 存在共享冲突
- 源文件或目标文件(source or destination file)可能正在使用中
- 该文件正被另一个程序或用户使用(program or user)
- 确保(Make)磁盘未满或未写保护并且文件当前未在使用中
程序非常轻量级,根本不占用太多资源。它还可以告诉您有关Windows进程的许多其他信息,但这是另一篇文章。就像我上面所说的,如果有人拒绝您手动访问,除非您获得管理员的许可,否则您将无法进入该文件夹或文件!(folder or file)有任何问题,发表评论。享受!
How to Fix Access is Denied, File May Be In Use, or Sharing Violation Errors in Windows
Ever try to delete a file and get an Access is Denied error? Or maybe you’re trying to copy or move a file or folder and you get a message stating the source file may be in use? This type of error can occur for several reasons: you do not have ownership of the file or folder and therefore cannot perform any actions on it or the operating system or another program is currently using it.
You can usually figure out which situation you’re involved with by taking a look at what exactly you’re trying to do. If you get the Access is Denied or You don’t currently have permission to access this folder message, then you’re probably looking at a permissions problem. If you’re not an Administrator on the computer, you’re probably not going to be able to fix this issue, so first make sure you can get access to an admin account.
Access Is Denied Error
This particular error is normally caused by NTFS permissions, but it can also be caused by other issues like a corrupt user profile, encryption on the file or if the file is in use. We’ll talk about file in use errors in the next section.
To gain access to the file or folder, you’ll need to have the correct permissions configured for your account. Before you start doing any work, you should try to click on the Continue button that will show up in Windows 7 and Windows 8 automatically. This will try to give your user account permissions to the folder as long as you are the owner.
If you get the You have been denied permission to access this folder message after clicking Continue, that means you are not the owner and you’ll have to first take ownership of the folder before you can change any permissions.
Take Ownership of Files and Folders in Windows
Taking ownership is unfortunately quite a process, so it’s best to have ample time and patience before attempting this. To get started, you need to right-click on the file or folder, choose Properties and then go to the Security tab.
If you have no access to the folder, you’ll see a message stating you have to be an Administrator to view the security properties. Go ahead and click on Continue. This will pop up another dialog where you get the option to change the owner.
In the Change owner to box, select your user account or Administrators. I personally choose my own account because that’s the default behavior in Windows when you create a new folder/file. Also make sure to check the Replace owner on subcontainers and objects box. Click OK and you’ll get another message saying you don’t have permissions to read the contents, do you want to replace permissions and grant yourself Full Control. Click Yes.
Now make sure to click OK on any remaining open windows so that all dialogs are closed. Don’t try to change any other settings at this point. You have to first close any open dialogs and go back to the Explorer screen. Once there, again right-click on the file/folder and choose Properties and go to the Security tab. It should now look a bit different.
You can access the contents of the file/folder at this point, but it’s best to reset the permissions completely. At this point, you have just added yourself and that’s it. If you want the default Windows permissions that would be applied, you can follow the next couple of steps. Click on the Advanced button and then click on Change Permissions.
Click the Remove button and remove all of the permissions currently listed. At this point, it should just be your user account. Once the listbox is empty, go ahead and check the Include inheritable permissions from this object’s parent box. Then click the Apply button, not the OK button.
You should see several entries appear in the listbox, including one for your user account. The default permissions also include SYSTEM and Administrators usually, so it’s a good idea to reset them properly this way. If the folder has many sub-folders with files, you can check the Replace all child object permissions with inheritable permissions from this object box. Close all dialogs and you should be good to go!
As I mentioned earlier, Access is Denied can be caused in some cases by other issues. A corrupt user profile is one of those odd issues that I have seen more in domain environments. You can create a new user profile and then try to access the file or folder.
The other issue is if the file is encrypted. You can always try checking to see if the file is encrypted or not by right-clicking and choosing Properties. Then click on the Advanced button from the General tab and uncheck the Encrypt contents to secure data box.
If someone else has encrypted the file/folder, you won’t be able to access it until you can decrypt it using their user account. The last issue if the file itself is corrupt. In that case, you will have to search for software that can help repair corrupt files, though this is a very rare cause of the problem.
File in Use or Sharing Violation Error
Note that getting the Access is Denied message can be caused by a sharing violation, so if the above method did not work, try the following procedure below.
You can download and install a free program called Process Explorer from Microsoft. You can use it to find out which processes are locking up a file. Right-click on the executable file after unzipping and choose Run as Administrator to run the program. Then don’t worry about all the crazy colors and bars, just go to the top and click on Find and then Find Handle or DLL.
Now type in the name of the file in question in the box and type search. You don’t have to type the full name of the file; just part of it will also work most of the time.
You should get back a list of processes that currently have locks on the file. In my case, Notepad.exe locked my test document. Now select the item in the box and then close the search box. You should be back at the main process explorer screen. At the bottom, a row should be highlighted and it should be the path to the file that you had selected in the search box.
Right-click on that row and choose Close Handle. If there was more than one process in the search box, you will have to repeat the same procedure for each process. At this point, you should be able to delete or modify the file as you please. The program is very useful when you get these types of error messages:
- Cannot delete file: Error 5 Access is denied
- There has been a sharing violation
- The source or destination file may be in use
- The file is in use by another program or user
- Make sure the disk is not full or write-protected and that the file is not currently in use
Program is very lightweight and does not take up very many resources at all. It can also tell you a lot of other information about Windows processes, but that’s for another post. Like I said above, if someone has denied you access manually, you will not be able to get into that folder or file unless you are given permissions from an Administrator! Have any questions, post a comment. Enjoy!