How to unlock a file handle locked by SYSTEM or any other active process in Windows

The scenario we’re about to introduce is an unbeatable classic for anyone working with Windows. You need to move, rename or delete a file and – as soon as you try to do that – you’re greeted by the following popup message:

File in Use. The action can’t be completed because the file is open in another program.

Or maybe this one:

The action cannot be completed because the file is open in SYSTEM.

If you’re an experienced Windows user you most certainly know that, when you see something like this, it usually means that there is a running application which still has that file opened in an exclusive mode – thus locking it from any IO write operations: no rename, no move and certainly no delete. Whenever that’s the case, the fix is right around the corner: you close the offending application – be it MS Word, MS Excel, MS Access, Photoshop and so on – then go back to the file and do whatever you want with it. Problem solved!

What to do when there are no active applications that seems to be locking that file? As soon as you are sure about it you can focus your attention to other Windows processes, such as some active services that could have it open: Antivirus software, Database services, Source Control Managers, Software Optimizers, Backup Tools, Firewall/security systems and so on. Again, if you’re a seasoned Windows user, you will have no problem to figure it out soon enough.

However there is always a small chance that, after you spent a reasonable amount of time checking and/or temporarily shutting down your resident software, you would still have absolutely no idea of what process is actually keeping that file open. Whenever this happens, you’re going to equip yourself with a few freeware tools that might really help you fixing your issue for good.

Solution #1 (bad): Unlocker

If we don’t want to bother about what’s happening to our system and just want to release that damn file we can think about trying to use Unlocker, a freeware application made by Cedrick Collomb that could automatically fix your issue… or not! I personally don’t recommend using this software for at least two reasons:

  1. You won’t learn anything from using that, including what process (or process chain) will be abruptly shutdown with the intent to free your file.
  2. The program is freeware, but it carries a huge amount of bloatware you need to opt-out from: doing that will even require some attention, because the setup program will try to guide you into installing them and I just really don’t like it.

As a viable alternative you could also try IOBit Unlocker, which is basically the IOBit attempt to capitalize the “unlocker” brand because the original author didn’t make it into a commercial hit (yet). The software is also freeware (+bloatware offers) and it does nothing more, nothing less than the former one, thus being just as bad.

Solution #2 (good): Process Explorer

With Sysinternals Process Explorer (or simply ProcessExplorer) things start looking good. This small, yet great portable utility (no setup, just download and run) allows you to see all the currently active processes within your system, including the names of their owning accounts and a full list of handles (files) that the process selected in the top window has opened, including (if we switch it to DLL mode) the system DLLs: this basically means that we can fully understand what’s going on, and which process is holding our files.

How to unlock a file handle locked by SYSTEM or any other active process in Windows

The tool also features a powerful search capability that will quickly show you which processes have particular handles opened or DLLs loaded. This will allow us to use it to easily fix most unwanted file locks in a matter of seconds: we just have to search for the locked file, retrieve the process which is keeping the handle and close (or kill) it accordingly.

 

Solution #3 (great): Handle

SolutionExplorer is a great analysis tool, yet it lacks some useful options to actually fix our specific issue: altough we can use it to kill a whole process, it doesn’t provide a way to release a specific handle: whenever we’re dealing with files locked by processes we cannot kill, such as SYSTEM, this can be a problem. In order to achieve such surgical result we need to get our hands to another great Sysinternals utility that goes by the name of Handle.

Handle is basically the console version of ProcessExplorer: think of it like a ProcessExplorer with command-line options instead of the GUI. This could make it less intuitive when we need to investigate our system, yet it has extremely powerful tools when it comes to fix the issues we found.

The most common usage of Handle – for our specific scenario – is the following:

  • Download Handle and unzip it into a folder of your choice.
  • Open a command prompt window with administrative priviledges and input the following command:  . The tool will then create a list of active processes/handles and write the (huge) outcome into the output.txt file.
  • Do not close the command prompt, as you will need it again. Open the output.txt file with your favourite text editor and search for a row containing your locked file name. Once you find it, look for the HEX number to the left and write it down: this is the ID of the handle you need to close. Right after that, go up through the file until you reach the parent row, which contains the informations about the process which is holding that handle. Again, look for the small HEX number to the left and write it down: this is the ID of the process you’ll need to use in the following step. As a side note: SYSTEM process ID is usually 4, although it could vary in the future.
  • Go back to the command prompt and try to close the handle by typing the following:  , replacing the placeholders with the values you found in the previous step.

If everything goes correctly, you will fix your problem without killing the process and – more importantly – without having to reboot the system.

That’s it for now: happy “handling”!

 

 

RELATED POSTS

About Ryan

IT Project Manager, Web Interface Architect and Lead Developer for many high-traffic web sites & services hosted in Italy and Europe. Since 2010 it’s also a lead designer for many App and games for Android, iOS and Windows Phone mobile devices for a number of italian companies.

View all posts by Ryan