1117

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?

bwDraco
  • 45,079
  • 43
  • 163
  • 201
leeand00
  • 20,038
  • 39
  • 115
  • 177
  • 7
    See [this ServerFault question](http://serverfault.com/questions/1966/how-do-you-find-what-process-is-holding-a-file-open-in-windows/). – John Fouhy Jul 17 '09 at 03:34
  • 1
    Is your file a video? You may find that Windows Explorer itself is "using" the file... – DisgruntledGoat Mar 12 '12 at 10:32
  • 54
    How 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. – arkon Mar 16 '15 at 02:15
  • 13
    I 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 Jun 15 '15 at 00:54
  • 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 Jul 12 '16 at 22:53
  • 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 Jan 24 '19 at 15:25
  • 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 Sep 01 '19 at 17:35
  • 10
    Imagine living in 2021 and Windows still doesn't just tell you which process is using the file when it reports the error. – BadHorsie Apr 22 '21 at 14:59

12 Answers12

1313

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

  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
  • 36,130
  • 59
  • 132
  • 178
  • 36
    Note: the Resource Monitor didn't find any associated handles in my case whereas Process Explorer (as [described above](http://superuser.com/a/399660/137286)) did. – ComFreek May 06 '14 at 16:57
  • 28
    @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 May 06 '14 at 21:16
  • 11
    I couldn't find this in Process Explorer, but it was easy to locate with these instructions in Resource Manager. Thanks. – Tatiana Racheva Aug 08 '14 at 04:30
  • 9
    @ComFreek In my case it was just the other case: Process Explorer didn't find the handle, whereas Resource Monitor did. – Uwe Keim Nov 25 '15 at 13:24
  • 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 Feb 21 '16 at 23:13
  • 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 – jb007 Nov 15 '16 at 07:18
  • 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 Feb 25 '17 at 00:34
  • 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 May 26 '18 at 16:47
  • 1
    Doesn't seem to work for locked folders – Hack-R Jul 05 '18 at 21:50
  • @Svish, what to do if the file is locked by a proccess running on another machine within the local network? – Anton Shepelev Sep 04 '18 at 12:40
  • @Ant_222 I dunno? Kill the connection? Send up a bat-signal? – Svish Sep 14 '18 at 10:07
  • 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 Apr 17 '19 at 16:40
  • How does this works for folders? I put the name of the folder, nothing happened – KansaiRobot Apr 22 '19 at 05:59
  • 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 Apr 24 '19 at 12:22
  • One of the few cases where GUI triumphs over command line in usability. Don't need to enable non-default tracking of open files to use perfmon! – BobHy Apr 12 '20 at 15:36
  • This used to work for me. Since then I've upgraded to win 10, the offending process never showed as owning any files (admittedly, run from within Visual Studio.) – Loren Pechtel Nov 16 '20 at 02:12
  • worked when given the full path. – hafiz ali Jun 17 '21 at 11:31
  • Is there a command-line method? – szx Nov 13 '21 at 10:47
  • @szx https://stackoverflow.com/a/958180/39321 – Svish Nov 15 '21 at 09:30
  • This worked for a locked folder as well (folder was locked by Windows Explorer) – David.P Mar 30 '22 at 15:08
444

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
  • 16,272
  • 6
  • 44
  • 75
  • 34
    In 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 Sep 25 '12 at 17:16
  • 14
    NOTE: Unlocker installs Adware if you are not careful. From their website: "Promotional feature: Fully optional Delta toolbar." – Julian Knight Mar 13 '14 at 21:50
  • 12
    @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 Jul 01 '14 at 20:19
  • WhoLockMe states it's for Win NT to XP. Does it work on higher? – jpmc26 Sep 19 '14 at 16:01
  • 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 Sep 24 '14 at 19:28
  • 6
    @jpmc26 No. WhoLockMe does not work on Windows 7. – ceving Nov 28 '14 at 19:39
  • 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! – sheldonhull Dec 26 '14 at 20:17
  • The first link looks like it is broken and the second doesn't look like it is working in Windows 10 – Serj Sagan Sep 10 '15 at 01:44
  • 4
    @GarryEnglish- As stated by GuiSim, this is for sure not always the case, and in my experience, it is rarely the case. – dgo Sep 14 '15 at 16:03
  • 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 Nov 05 '15 at 14:46
  • 1
    @abourget - why not add that as an alternative answer then – Shevek Nov 05 '15 at 15:51
  • would be nice if in the answer you also explained that wholockedme doesn't work on windows 7! – davejal Dec 20 '16 at 13:35
  • @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 Dec 20 '16 at 17:26
  • 2
    It 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 Oct 17 '17 at 07:20
  • WhoLockMe link is not safe, there is XSS fail !!! – Sky Voyager Apr 04 '20 at 12:50
  • Thanks for the "Find Handle or DLL" suggestion. I run across a locked folder a lot. Always takes a reboot to be able to delete them. Every other suggestion on this page only ever tells me that explorer has it open. Nope! Restarting explorer never worked. Usually it's something dumb like Notepad remaining live. But in this case it listed explorer AND some other oddball process I hadn't noticed. – Justin Emlay Jun 01 '20 at 00:36
  • `WhoLocksMe` looks abandoned and the web site doesn't look trustworthy. I don't recommend to use this tool. There are better alternatives mentioned in this thread like [Lock Hunter](https://superuser.com/a/400394/1182474) and [OpenedFilesView](https://superuser.com/a/1485069/1182474) – PolarBear Jul 20 '21 at 13:00
250

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

Peter Mortensen
  • 11,880
  • 23
  • 69
  • 90
Eroen
  • 6,223
  • 1
  • 16
  • 25
  • 9
    Process Hacker also can do it. – Benoit Mar 12 '12 at 10:41
  • 7
    As [another answer](http://superuser.com/a/6614/820) mentions, [Handle](http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx) is a command line tool from SysInternals that will also accomplish this task. – heavyd Dec 11 '13 at 22:35
  • I forgot a cmd proces open in the folder, proces explorer helped me notice it. – davejal Dec 20 '16 at 13:33
  • Note to Googlers, current version of PE appears to no longer support **Close Handle** – MickyD Dec 12 '17 at 08:09
  • Failed to work in Win10 64-bit 1709 – K7AAY Aug 30 '18 at 15:39
  • `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 Nov 22 '18 at 15:47
  • Work for me in Win10 64-bit 1809 – Josem Feb 15 '19 at 16:21
132

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 archive

Wouter
  • 129
  • 1
  • 7
frank
  • 1,556
  • 1
  • 8
  • 3
  • For some reason this just returned an empty string for me. I did run PS ISE in administrator mode too. – Dib Jun 26 '17 at 11:52
  • 20
    The feature must first be enabled with `openfiles /local on` – mstrange Jul 05 '17 at 17:02
  • 9
    Unfortunately, `openfiles` seems not to work on a 64-bit Windows: `ERROR: The target system must be running a 32 bit OS.` – Thomas S. Nov 02 '17 at 10:55
  • 1
    Works on Win10 64 for me – Michael Feb 07 '18 at 21:12
  • 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 Jun 20 '18 at 16:40
  • 7
    It looks like you could basically achieve it in pure cmd with`openfiles /query /fo table | find /I ""`? – mwfearnley Aug 31 '18 at 11:30
  • 10
    ...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. – Nic Jun 22 '19 at 21:00
  • There is not even specified, what to restart. – Salda Jun 23 '19 at 11:47
  • 4
    @NicHartley Because enabling it would allow it to work next time. – Bill K Oct 22 '19 at 20:28
  • 2
    Instead of `openfiles` you can use a similar tool [Handle from Sysinternals](https://docs.microsoft.com/en-us/sysinternals/downloads/handle): `handle.exe -u -nobanner -accepteula "C:\FileOrFolderForWhichWeWantToFindLockingInformation"` – PolarBear Jul 20 '21 at 11:24
63

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
  • 54,414
  • 49
  • 189
  • 248
14

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é
  • 3,229
  • 1
  • 18
  • 23
  • @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é Mar 12 '12 at 03:46
11

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
  • 1,102
  • 13
  • 31
7

I have created a small utility ShowWhatProcessLocksFile which shows what processes lock a selected file or folder (for example, on the screenshot bellow you can see the view of all processes which lock C:\Program Files folder). The program integrates into the File Explorer's context menu to allow selecting a file or folder. Note: the application requires admin permissions. Screenshot

PolarBear
  • 231
  • 2
  • 5
5

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
  • 51
  • 1
  • 1
3

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
  • 169
  • 3
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.

jonsca
  • 4,077
  • 15
  • 34
  • 46
0

I am not sure if anyone used Process Viewer (PVIEW.exe). I was having trouble finding out the process that locked my epmd.exe which i was trying to delete, when I searched for Process Explorer app in my Windows 10 box - I found this app. So, I thought of giving it a try and it worked (so, this can be another option):

This app existed at the following location for me - C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT\Tools\PVIEW.EXE

enter image description here

Look for your locked application (file), and Kill Process to unlock the file.

Sri Reddy
  • 121
  • 1