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

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?

• Jul 17, 2009 at 3:34
• Is your file a video? You may find that Windows Explorer itself is "using" the file... Mar 12, 2012 at 10:32
• 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. Mar 16, 2015 at 2:15
• 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. Jun 15, 2015 at 0:54
• Imagine living in 2021 and Windows still doesn't just tell you which process is using the file when it reports the error. Apr 22, 2021 at 14:59

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.

• The feature must first be enabled with openfiles /local on Jul 5, 2017 at 17:02
• Unfortunately, openfiles seems not to work on a 64-bit Windows: ERROR: The target system must be running a 32 bit OS. Nov 2, 2017 at 10:55
• It looks like you could basically achieve it in pure cmd withopenfiles /query /fo table | find /I "<path>"? Aug 31, 2018 at 11:30
• ...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, 2019 at 21:00
• @NicHartley Because enabling it would allow it to work next time. Oct 22, 2019 at 20:28

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!

• Note: the Resource Monitor didn't find any associated handles in my case whereas Process Explorer (as described above) did. May 6, 2014 at 16:57
• @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. May 6, 2014 at 21:16
• I couldn't find this in Process Explorer, but it was easy to locate with these instructions in Resource Manager. Thanks. Aug 8, 2014 at 4:30
• @ComFreek In my case it was just the other case: Process Explorer didn't find the handle, whereas Resource Monitor did. Nov 25, 2015 at 13:24
• @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. Feb 25, 2017 at 0:34

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.

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).

• In Windows 7, if you try to delete a file that is locked, the error message will tell you which process has it locked Sep 25, 2012 at 17:16
• NOTE: Unlocker installs Adware if you are not careful. From their website: "Promotional feature: Fully optional Delta toolbar." Mar 13, 2014 at 21:50
• @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. Jul 1, 2014 at 20:19
• @jpmc26 No. WhoLockMe does not work on Windows 7. Nov 28, 2014 at 19:39
• @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, 2015 at 16:03

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.

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

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.

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

• Process Hacker also can do it. Mar 12, 2012 at 10:41
• As another answer mentions, Handle is a command line tool from SysInternals that will also accomplish this task. Dec 11, 2013 at 22:35
• I forgot a cmd proces open in the folder, proces explorer helped me notice it. Dec 20, 2016 at 13:33
• Note to Googlers, current version of PE appears to no longer support Close Handle Dec 12, 2017 at 8:09
• Failed to work in Win10 64-bit 1709 Aug 30, 2018 at 15:39

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
• Top 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. Jul 19, 2016 at 17:45
• Luck hunter has worked for me when others haven't Dec 8, 2016 at 23:13
• This is great but the portable version doesn't integrate with the explorer menu Nov 1, 2021 at 13:28
• This worked for me on a folder. Other methods did not work for me since I didn't know which file was locked. Jul 20, 2022 at 12:51
• THE TRUE BEST SOLUTION — in that it requires the least manual effort among all the answers. Nov 12, 2022 at 16:46

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.

• @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). Mar 12, 2012 at 3:46

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

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

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.

This tool still works reliably in 2019

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.

• “This tool is [[*was]] inspired by LockHunter.” What’s the difference between the two? Nov 12, 2022 at 16:40
• This works! After installing, go to Windows Explorer and right-click on the file or folder of interest; the context menu shows an entry for this application. When selected, a window appears that actually shows what is locking the file AND there is a little "minus sign" in the toolbar that kills the selected process. Wow! Why doesn't Windows already have this option? Why is this so difficult to do in 2022? Thanks! Dec 22, 2022 at 3:52

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

• This will only work for shared folders. Aug 14, 2013 at 3:57

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.

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.

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

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

You can also do it programmatically by leveraging on the NTDLL/KERNEL32 Windows API. E.g. have a look at the following code in Python which returns a list of PIDs that can then easily be killed using the Task Manager or similar tools.

import ctypes
from ctypes import wintypes

path = r"C:\temp\test.txt"

# -----------------------------------------------------------------------------
# generic strings and constants
# -----------------------------------------------------------------------------

ntdll = ctypes.WinDLL('ntdll')
kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)

NTSTATUS = wintypes.LONG

INVALID_HANDLE_VALUE = wintypes.HANDLE(-1).value
OPEN_EXISTING = 3
FILE_FLAG_BACKUP_SEMANTICS = 0x02000000

FILE_INFORMATION_CLASS = wintypes.ULONG
FileProcessIdsUsingFileInformation = 47

LPSECURITY_ATTRIBUTES = wintypes.LPVOID
ULONG_PTR = wintypes.WPARAM

# -----------------------------------------------------------------------------
# create handle on concerned file with dwDesiredAccess == FILE_READ_ATTRIBUTES
# -----------------------------------------------------------------------------

kernel32.CreateFileW.restype = wintypes.HANDLE
kernel32.CreateFileW.argtypes = (
wintypes.LPCWSTR,      # In     lpFileName
wintypes.DWORD,        # In     dwDesiredAccess
wintypes.DWORD,        # In     dwShareMode
LPSECURITY_ATTRIBUTES,  # In_opt lpSecurityAttributes
wintypes.DWORD,        # In     dwCreationDisposition
wintypes.DWORD,        # In     dwFlagsAndAttributes
wintypes.HANDLE)       # In_opt hTemplateFile
hFile = kernel32.CreateFileW(
FILE_FLAG_BACKUP_SEMANTICS, None)
if hFile == INVALID_HANDLE_VALUE:
raise ctypes.WinError(ctypes.get_last_error())

# -----------------------------------------------------------------------------
# prepare data types for system call
# -----------------------------------------------------------------------------

class IO_STATUS_BLOCK(ctypes.Structure):
class _STATUS(ctypes.Union):
_fields_ = (('Status', NTSTATUS),
('Pointer', wintypes.LPVOID))
_anonymous_ = '_Status',
_fields_ = (('_Status', _STATUS),
('Information', ULONG_PTR))

iosb = IO_STATUS_BLOCK()

class FILE_PROCESS_IDS_USING_FILE_INFORMATION(ctypes.Structure):
_fields_ = (('NumberOfProcessIdsInList', wintypes.LARGE_INTEGER),
('ProcessIdList', wintypes.LARGE_INTEGER * 64))

info = FILE_PROCESS_IDS_USING_FILE_INFORMATION()

PIO_STATUS_BLOCK = ctypes.POINTER(IO_STATUS_BLOCK)
ntdll.NtQueryInformationFile.restype = NTSTATUS
ntdll.NtQueryInformationFile.argtypes = (
wintypes.HANDLE,        # In  FileHandle
PIO_STATUS_BLOCK,       # Out IoStatusBlock
wintypes.LPVOID,        # Out FileInformation
wintypes.ULONG,         # In  Length
FILE_INFORMATION_CLASS)  # In  FileInformationClass

# -----------------------------------------------------------------------------
# system call to retrieve list of PIDs currently using the file
# -----------------------------------------------------------------------------
status = ntdll.NtQueryInformationFile(hFile, ctypes.byref(iosb),
ctypes.byref(info),
ctypes.sizeof(info),
FileProcessIdsUsingFileInformation)
pidList = info.ProcessIdList[0:info.NumberOfProcessIdsInList]
print(pidList)