Find out which process is locking a file or folder in Windows

768

268

How can I find out which process is locking a file or folder in Windows?

For instance, when trying to delete a folder, Windows reports this:

The action can't be completed because the folder is open in another program

Happens the same with a file, but how do I find out what program or application is currently using it and preventing me from deleting the file or folder?

leeand00

Posted 2010-03-09T14:05:19.753

Reputation: 14 882

38How is this a duplicate? He's specifically asking how to find out which process is locking a file, not how to delete a locked file. – b1nary.atr0phy – 2015-03-16T02:15:07.187

9I can't add an built-in, simpler answer here because it was incorrectly marked as a dupe, nor can I add it to the other thread because that only applies to XP. But anyway, for Windows versions with Resource Monitor (type it in search bar), go to CPU tab/Associated Handles, then search for the file or folder. – jontyc – 2015-06-15T00:54:05.657

I learned that Windows 10 (and I guess as early as Windows 7) has a program called Resource Monitor, which lets you see what processes are locking a file or folder: http://stackoverflow.com/a/24126882/470749

– Ryan – 2016-07-12T22:53:15.690

When I delete the file the actual dialog box indicates which process is locking it. I only mention it because I've only now noticed it after searching for a way to find which process is preventing me from deleting it. – Corey Alix – 2019-01-24T15:25:59.480

Neither of the answers below helped me to delete an .iso file, and then I looked into Hyper-V manager, and one the virtual machines used the .iso file as source for DVD drive. – Roman O – 2019-09-01T17:35:20.410

5

See this ServerFault question.

– John Fouhy – 2009-07-17T03:34:42.863

1Is your file a video? You may find that Windows Explorer itself is "using" the file... – DisgruntledGoat – 2012-03-12T10:32:28.973

Answers

76

PowerShell method:

IF((Test-Path -Path $FileOrFolderPath) -eq $false) {
    Write-Warning "File or directory does not exist."       
}
Else {
    $LockingProcess = CMD /C "openfiles /query /fo table | find /I ""$FileOrFolderPath"""
    Write-Host $LockingProcess
}

The openfiles command needs to have support for local files enabled, by running openfiles /local on and restarting.

More details How to find out which process is locking a file or folder in Windows

frank

Posted 2010-03-09T14:05:19.753

Reputation: 906

For some reason this just returned an empty string for me. I did run PS ISE in administrator mode too. – Dib – 2017-06-26T11:52:11.910

12The feature must first be enabled with openfiles /local on – mstrange – 2017-07-05T17:02:59.670

6Unfortunately, openfiles seems not to work on a 64-bit Windows: ERROR: The target system must be running a 32 bit OS. – Thomas S. – 2017-11-02T10:55:13.747

1Works on Win10 64 for me – Michael – 2018-02-07T21:12:50.153

Running this gave me the same Access is Denied error I was getting originally, and then always printed out the does not exist error message. The below answer, however, gave me the information I needed - IIS was locking the directory I needed to change. – Chris Thompson – 2018-06-20T16:40:51.173

3It looks like you could basically achieve it in pure cmd withopenfiles /query /fo table | find /I "<path>"? – mwfearnley – 2018-08-31T11:30:50.777

2...If we're willing to restart to enable something, why wouldn't we just restart to access the folder? I don't get how this solved OP's problem when "just reboot your machine" would have been much easier and still required a reboot. – Fund Monica's Lawsuit – 2019-06-22T21:00:48.450

There is not even specified, what to restart. – Salda – 2019-06-23T11:47:53.693

1@NicHartley Because enabling it would allow it to work next time. – Bill K – 2019-10-22T20:28:25.440

776

You can use the Resource Monitor for this which comes built-in with Windows 7, 8, and 10.

  1. Open Resource Monitor, which can be found
    • By searching for Resource Monitor or resmon.exe in the start menu, or
    • As a button on the Performance tab in your Task Manager
  2. Go to the CPU tab
  3. Use the search field in the Associated Handles section
    • See blue arrow in screen shot below

When you've found the handle, you can identify the process by looking at the Image and/or PID column.

You can then try to close the application as you normally would, or, if that's not possible, just right-click the handle and kill the process directly from there. Easy peasy!

Resource Monitor screenshot

Svish

Posted 2010-03-09T14:05:19.753

Reputation: 27 731

10I couldn't find this in Process Explorer, but it was easy to locate with these instructions in Resource Manager. Thanks. – Tatiana Racheva – 2014-08-08T04:30:00.193

7@ComFreek In my case it was just the other case: Process Explorer didn't find the handle, whereas Resource Monitor did. – Uwe Keim – 2015-11-25T13:24:45.430

I tried to end the process and was told, "When attempting to execute the command, the following system error occurred: Access is denied." I had Resource Monitor running as admin. – Shaun Luttin – 2016-02-21T23:13:08.600

10+1 - this also works just fine on Windows 10 – Matt Innes – 2016-06-01T15:03:02.430

For me it was an actual folder that was locked. Resource monitor search for folder name gave me imagine result, and ending that process unblocked the folde.r – joey – 2016-11-15T07:18:31.247

1@ComFreek For me, the opposite was actually true. I.e. Process Explorer didn't find anything, whereas Resource Monitor did. I'm using Windows 10. – Miscreant – 2017-02-25T00:34:58.383

Works for me. Since my error was a python-related error, I had to make sure to get rid of the double backslashes to fit Window's search criteria. – moondra – 2018-05-26T16:47:46.710

1Doesn't seem to work for locked folders – Hack-R – 2018-07-05T21:50:51.940

@Svish, what to do if the file is locked by a proccess running on another machine within the local network? – Ant_222 – 2018-09-04T12:40:28.033

@Ant_222 I dunno? Kill the connection? Send up a bat-signal? – Svish – 2018-09-14T10:07:12.553

I've rarely, if ever had success with Process Explorer, but this Resource Monitor method has just worked perfectly for me twice this morning when a folder was locked. PE was unable to find the correct process, it just kept saying explorer.exe had it locked. Resmon correctly identified two different processes in two cases. Based on a ratio of upvotes, it appears Resmon is working more on average than PE. – SSilk – 2019-04-17T16:40:08.407

How does this works for folders? I put the name of the folder, nothing happened – KansaiRobot – 2019-04-22T05:59:42.763

Seems to work the same for me. I created a folder, navigated to it using cmd, and the folder (with no files in it) showed up in the Associated Handles for cmd.exe. The type is listed as File though, so I guess resmon (or the file system maybe?) doesn't really distinguish between the two. A file handle is a file handle, regardless, maybe. ‍♂️ – Svish – 2019-04-24T12:22:03.127

19

Note: the Resource Monitor didn't find any associated handles in my case whereas Process Explorer (as described above) did.

– ComFreek – 2014-05-06T16:57:52.517

17@ComFreek Well, ProcessExplorer might be more powerful in many cases, but for me Resource Monitor have always found the application locking the file I'm trying to do something with. I also prefer it to Process Explorer simply because it's right there in the OS. No need for an extra download and an extra shortcut somewhere. – Svish – 2014-05-06T21:16:13.963

396

A couple of options:

Microsoft/SysInternals Process Explorer - Go to Find > Find Handle or DLL. In the "Handle or DLL substring:" text box, type the path to the file (e.g. "C:\path\to\file.txt") and click "Search". All processes which have an open handle to that file should be listed.

WhoLockMe - Explorer extension which adds a right-click menu option

N.B. WhoLockMe appears to not work with Win 10 (at least I have been unable to register it with either of the 32- or 64-bit versions of regsvr32.exe).

Shevek

Posted 2010-03-09T14:05:19.753

Reputation: 15 408

11@GarryEnglish for some reason this isn't always the case. I just had to use procexp to tell me that notepad++ had a lock on a folder. Windows 7 was unable to tell me the culprit. – GuiSim – 2014-07-01T20:19:43.443

WhoLockMe states it's for Win NT to XP. Does it work on higher? – jpmc26 – 2014-09-19T16:01:21.930

1@jpmc26 I have no idea.. I've stopped using it in favour of Unlocker which has a nicer interface IMHO. Unlocker was in my original answer but was edited out because it later had adware added to the installer. – Shevek – 2014-09-24T19:28:39.800

4@jpmc26 No. WhoLockMe does not work on Windows 7. – ceving – 2014-11-28T19:39:53.097

FYI, I use process hacker. I found a user for the search for Handle button now! It identified a minimized to tray cmd window I had open in the folder that was locking it. Thanks for the tip! – SheldonH – 2014-12-26T20:17:47.457

The first link looks like it is broken and the second doesn't look like it is working in Windows 10 – Serj Sagan – 2015-09-10T01:44:16.510

3@GarryEnglish- As stated by GuiSim, this is for sure not always the case, and in my experience, it is rarely the case. – dgo – 2015-09-14T16:03:10.550

Powershell would be quicker, less bloated than all those apps suggestions, see: https://beamusupscotty.wordpress.com/2012/11/14/use-powershell-to-find-out-which-process-locks-a-file/

– abourget – 2015-11-05T14:46:52.017

1@abourget - why not add that as an alternative answer then – Shevek – 2015-11-05T15:51:49.180

would be nice if in the answer you also explained that wholockedme doesn't work on windows 7! – davejal – 2016-12-20T13:35:29.840

@davejal I have no idea what operating systems wholockedme works with as I have never heard of it and don't even mention it in my answer WhoLockMe on the other hand works great on Win7 – Shevek – 2016-12-20T17:26:44.203

2It should be noted that process explorer has to be run as adminstrator. Ran it on Windows 10 as normal user and it didn't work. – Devolus – 2017-10-17T07:20:26.767

ooops! That comment was meant for another answer... :) – not2qubit – 2018-11-22T15:42:32.243

28In Windows 7, if you try to delete a file that is locked, the error message will tell you which process has it locked – Garry English – 2012-09-25T17:16:25.083

11NOTE: Unlocker installs Adware if you are not careful. From their website: "Promotional feature: Fully optional Delta toolbar." – Julian Knight – 2014-03-13T21:50:09.653

203

Have a look at Process Explorer (procexp.exe).

From its introduction:

Ever wondered which program has a particular file or directory open? Now you can find out.

To find out what process is using a specific file follow these steps:

  1. Go to Find, Find Handle or DLL.. or simply press Ctrl+F.

    Enter image description here

  2. Enter the name of the file and press Search.

    Enter image description here

  3. Process Explorer will list all processes that have a handle to the file open. Click on an entry to focus the process in the main window.

    Enter image description here

  4. Optionally, you can then even close the handle manually through the lower pane (Ctrl+L):

    Enter image description here

Eroen

Posted 2010-03-09T14:05:19.753

Reputation: 5 615

I forgot a cmd proces open in the folder, proces explorer helped me notice it. – davejal – 2016-12-20T13:33:16.567

Note to Googlers, current version of PE appears to no longer support Close Handle – MickyD – 2017-12-12T08:09:26.067

Failed to work in Win10 64-bit 1709 – K7AAY – 2018-08-30T15:39:57.530

handle didn't work as expected (Win81). Reproduce: open some file in an editor, e.g. nano some.py, then try: handle.exe -nobanner some.py and get: No matching handles found. – not2qubit – 2018-11-22T15:47:06.787

Work for me in Win10 64-bit 1809 – Josem – 2019-02-15T16:21:16.940

7Process Hacker also can do it. – Benoit – 2012-03-12T10:41:58.557

5

As another answer mentions, Handle is a command line tool from SysInternals that will also accomplish this task.

– heavyd – 2013-12-11T22:35:11.117

34

LockHunter can unlock any handlers that may have locked your files or folders. Unlike similar freewares, it supports both 32 and 64-bit Windows.

It is a free tool to delete files blocked by something you do not know. LockHunter is useful for fighting against malware, and other programs that are blocking files without a reason. Unlike other similar tools it deletes files into the recycle bin so you may restore them if deleted by mistake.

  • Shows processes locking a file or folder
  • Allows to unlock, delete, copy or rename a locked file
  • Allows to kill locking process
  • Allows to remove locking processes from hard drive
  • Integrates in to Explorer menu
  • It deletes files into the recycle bin, so you may restore them if deleted by mistake
  • Supports both 32 and 64bit Windows

Mehper C. Palavuzlar

Posted 2010-03-09T14:05:19.753

Reputation: 51 093

5Top two answers didn't work me and the next upvoted ones were either blocked by my firewall or warned not to go to by my chrome!. LockHunter worked perfectly. – user3885927 – 2016-07-19T17:45:09.320

1Luck hunter has worked for me when others haven't – SheldonH – 2016-12-08T23:13:16.417

This one works. – jdhao – 2019-02-27T07:25:12.480

11

EMCO UnlockIT can identify the process that has locked the file as well as unlock the file so that you may delete/edit/move it. The program is completely free, though the newer version is a bit slower and more bloated than the original (which had a plain, unskinned GUI, but loaded pretty much instantaneously and without an annoying splash screen). Also, the original version used to pop up automatically whenever the error you mentioned is triggered, allowing you to instantly unlock the file and perform the operation you were attempting.

Still, UnlockIT is an incredibly useful program that provides a basic functionality that is critically missing from Windows. It's among the standard toolkit of utilities that I install on all Windows computers I work on.

Lèse majesté

Posted 2010-03-09T14:05:19.753

Reputation: 3 129

@John: Well, it does identify the program that has locked a file. And you can still manually kill the process through task manager. However, it's usually simpler to just unlock the file (especially when it's explorer that has locked the file most of the time) instead of having the kill the process that has locked it (usually due to having accessed the file and left the file handler open due to a program glitch). – Lèse majesté – 2012-03-12T03:46:46.790

4

A lot of the programs here are outdated. I finally ended up using nirsoft's OpenedFilesView which worked really well.

Screenshot

Though the best part is the explorer menu integration, which is easy to enable. As per website

Explorer Context Menu

Starting from version 1.10, you can launch OpenedFilesView directly from Windows Explorer, and view only the handles of the file or folder that you want to inspect. In order to enable this feature, check the 'Enable Explorer Context Menu' under the Options menu. After you enable this feature, you can right-click on any file or folder on Windows Explorer, and choose the 'OpenedFilesView' item from the menu. If you run the OpenedFilesView option for a folder, it'll display all opened files inside that folder. If you run the OpenedFilesView option for a file, it'll display all opened handles for that file.

context menu

This tool still works reliably in 2019

Vijay

Posted 2010-03-09T14:05:19.753

Reputation: 842

1Wonderful tool, as always with Nirsoft freeware! – Basj – 2019-11-12T10:34:18.623

4

If you do not know the program the file it is using then you can go to My Computer; right click; select Manage. Under System Tools > Shared folders > Open Files, you should be able to see the user who has locked the file. You can close file from here and then you can perform the task of rename or delete the file. Hope this helps

Rajesh

Posted 2010-03-09T14:05:19.753

Reputation: 41

1This will only work for shared folders. – sweetfa – 2013-08-14T03:57:23.397

3

Here was my discovery & solution.

Incidentally, none of the above answers solved my problem.

I even tried using UNLOCKER which proved worthless.

My problem was that of Memeo Autosync Backup

Apparently, this backup process leaves enough of a "ghost like file." This "ghost like file," would show up whenever I would ALT-TAB my computer (Windows Professional XP), i.e. I would see TWO MS Excel Programs running, when I only had ONE visible, on my TASK BAR.

I came across this solution when I thought it might have been the SYMANTEC Endpoint (Anti-Virus) Protection; and disabled the program. However, I kept getting the error message:

cannot delete (LARGE.xls file): It is being used by another person or program. Close any programs that might be using this file and try again.

I subsequently kept seeing the Memeo notice of "syncing" and QUIT the program.

Subsequently, NO ERROR.

For you, it could be ANY of these background saves.

formerly frustrated excel user

Posted 2010-03-09T14:05:19.753

Reputation: 31

2

Additional possibility, just to save people the time I just spent:

In older versions of Windows, you might get "Access Denied - you might not have rights, or the file might be in use". If you find through Process Explorer that the files are, in fact, not opened by anyone, odds are that there is an issue with security. Using an administrator account, select the files in Explorer, right-click and select Properties, Security, Advanced, Owner. Odds are that the files are owned by an account that no longer exists or can no longer be verified to exist (because of changing Active Directory trust settings).

Change ownership to Administrators and you are good to go.

Stu

Posted 2010-03-09T14:05:19.753

Reputation: 159