If I were to make a list of the most frustrating things that sometimes happen when using Windows (something my colleague Mitch Tulloch has already done), locked files would definitely be an item on the list. We have all occasionally received an error message stating that “the action can’t be completed because the folder or file is open in another program.” Most of the time, fixing the error is simply a matter of closing whichever application currently has the file open. Sometimes though, things aren’t that simple, and Windows claims that a file is locked, even though it isn’t actually open.
Unfortunately, there is no silver bullet solution or magical cure-all that will make this problem go away (with the possible exception of rebooting). There are, however, a number of different things that you can do to get to the root cause of the problem. Before I tell you what these possible remedies are, I need to point out that I am using Windows 10 as the basis for this article, although it is likely that the techniques that I am about to show you will also work in other Windows versions.
Windows locks certain types of files to prevent them from being modified simultaneously by two different users or two different applications. Normally, a file lock is engaged when the file is open, and Windows releases the lock when the application associated with the file is closed.
In my experience, two main things tend to cause files to remain locked even after their corresponding application is closed. One possibility is that temporary files used by the application were not properly cleared out when the application closed. Another possibility is that a portion of the application, such as an individual process, continues to run even though the application itself has been terminated.
Every application is different, so it can be a little bit tricky to track down the temporary files that are being used by a program. Thankfully, the issue of temporary files not being deleted properly is less common than that of processes not terminating properly.
Although an application could conceivably be designed to store its temporary files almost anywhere, there are two main locations that you should check. These include:
Go to these locations, and any other temporary file repository, and delete their contents. Typically, you will find that there were some files that you won’t be able to delete. There may be temporary files for example, that are actively being used by the operating system, and therefore cannot be deleted. It is normally safe to delete any temporary files that Windows is not currently using, but if you are concerned about causing damage then you can always create a backup of the files before removing them.
The more common cause for files remaining locked even after they have supposedly been closed is that an individual process associated with the application that had been using the file continues to run even though the application itself has been closed. While you can correct this problem by simply rebooting the machine, reboots tend to be inconvenient. Thankfully, there are ways to track down the offending process without having to reboot your computer.
The easiest thing that you can do is to open the Windows Task Manager, and simply browse the list of processes to see if there are any processes listed that correspond to the application that was last used to open the file. If you encounter such a process, then all you have to do is select the process, and then click on the End Task button.
Of course, there may be a large number of processes running on your computer, making it tricky to find the process that you are interested in. If that is the case, then it may be easier to use Windows PowerShell. Just use the Get-Process cmdlet, followed by the application name and an asterisk. Right now, for example, I am using an application called Dragon Naturally Speaking to dictate this article. If I wanted to use PowerShell to see if Dragon had any processes open, I could use this command:
As you can see in the figure below, PowerShell has returned a result. If you find a running process that should not be running, you can stop it by entering the Stop-Process cmdlet, followed by the -Name parameter, and the name of the process that you want to stop.
By far the best tool for tracking down the cause of a locked file is Process Explorer. Process Explorer is a free tool from Sysinternals. You can download Process Explorer here. You can see what Process Explorer looks like in the next screenshot.
As you look at the colorful screen capture above, you will notice that the toolbar contains an icon that looks like binoculars. Click on this icon to open the Process Explorer Search interface. Enter all or part of the name of your locked file, and then click the Search button. As you can see in the next figure, Process Explorer will show you exactly which process has the file locked.
When you click on the process within the list of results, Process Explorer will take you to the corresponding process within the overall list of processes. From there, all you have to do is to close the process.
It can be a maddening experience when Windows holds a file open even though it should be closed. Thankfully, it is usually relatively easy to get a locked file unlocked. If you find that none of the techniques that I have discussed can unlock your file (and you are sure that nobody else is using the file), then try emptying the Windows Recycle Bin and rebooting the computer. That will almost always fix the problem.
Featured image: Shutterstock
Docker and Microsoft have rolled out a new and easier way for developers to deploy…
The verify domain error when registering the same domain in Office 365 to a different…
When it comes to the bulk management of Hyper-V hosts (or of any Windows server,…
The Shiny Hunters hacking group has struck again. This time they hit meal-prep delivery company…
Specops uReset is an Active Directory password reset solution to handle the problem of forgotten…
According to several reports, eBay may be port scanning visitors to its site. While this…