- How to Identify which Windows Process is Locking a File or Folder
- Symptoms
- How to Solve the Issue
- Identify what program is using a file
- Identify which handle or DLL is using a file
- Release the lock on the file or folder
- How to Delete a Locked File in Windows 10
- How to Use Resource Monitor to Find Which Process Has Locked a File?
- View Associated Modules for a Process
- Related
- How to Identify the Process that has Locked a File in Windows
- Find which process has locked a file using:
- 1. Resource Monitor
- 2. Process Explorer
- 3. Handle from Windows Sysinternals
- Sysinternals Handle: Command-line arguments
- Add Sysinternals Handle to right-click menu
- 4. OpenFiles.exe — a built-in console tool
- Enable “Maintain Objects List” global flag for the First time
- View open files and the corresponding process names
- Disconnect files opened remotely from shared folder.
- 5. OpenedFilesView
How to Identify which Windows Process is Locking a File or Folder
While attempting to delete, move, or rename a file or folder you get a Windows warning message; the Operating System refuses to complete the operation.
This article helps identifying the process that currently has a handle on the file or folder you are attempting a maintenance operation on.
Symptoms
When trying to delete, move, or rename a file you get a Windows system warning message:
- «Cannot delete file: Access is denied».
- «There has been a sharing violation».
- «The source or destination file may be in use».
- «The file is in use by another program or user».
- «Make sure the disk is not full or write-protected and that the file is not currently in use».
How to Solve the Issue
One of the easiest ways to handle locked files or folders is to use Microsoft Sysinternals Process Explorer.
Identify what program is using a file
Using Process Explorer there is a simple way to find the program:
- Open Process Explorer
- Running as administrator.
- On the toolbar, find the gunsight icon on the right.
- Drag the icon and drop it on the open file or folder that is locked.
- The executable that is using the file will be highlighted in the Process Explorer main display list.
Identify which handle or DLL is using a file
- Open Process Explorer
- Running as administrator.
- Enter the keyboard shortcut Ctrl+F.
- Alternatively, click the “Find” menu and select “Find a Handle or DLL”.
- A search dialog box will open.
- Type in the name of the locked file or other file of interest.
- Partial names are usually sufficient.
- Click the button “Search”.
- A list will be generated.
- There may be a number of entries.
Release the lock on the file or folder
To release the lock on the file you are attempting the maintenance operation on, you will need to kill the appropriate process. An individual program or handle in the list provided by Process Explorer can be killed by:
- Selecting the process/handle/program entry.
- Pressing the delete key.
Proceed with care when deleting handles as this may generate erratic behavior and instabilities may occur.
How to Delete a Locked File in Windows 10
By Bryan Clark 04 July 2017
When you run into a locked folder in Windows 10, the system won’t allow you to do anything with it — open it, delete it, or move it — without the password. For folders that you didn’t lock, finding the password often isn’t an option. You can’t open these folders, but you can delete them — even though a simple right-click “Delete” won’t work, nor will the delete button.
It should be noted, however, that deleting these files could wreak havoc on your system if you’re not sure why they’re there in the first place. Proceed with caution.
1. Locate the folder you wish to delete. I don’t have any locked folders I’m willing to delete, so let’s create an unlocked folder — and call it SkypeHost.exe (a copy of an actual locked file) — for the sake of the tutorial. It works the same, but you can just as easily remove this folder with the delete button.
2. Download Process Explorer from Microsoft’s website, and press OK on the pop-up window.
3. Double click processexp64 to extract the file.
4. Choose Extract All.
5. Click Open.
6. Double click the procexp64 application to open the application.
7. Select Run.
8. Read the terms and press the Agree button.
9. In the Process Explorer window, choose File > Show Details for All Processes.
10. Allow the app to make changes by pressing the Yes button.
11. Go the the Find menu at the top and select Find Handle or DLL.
12. Type in the file name and hit Search.
13. Right click the process in the bottom of the Process Explorer screen and select Close Handle. If there are multiple processes listed here, you’ll need to repeat this step to close all of them.
14. Delete the file as you would normally.
How to Use Resource Monitor to Find Which Process Has Locked a File?
I know many folks that use Windows SysInternals Process Explorer to gather information about running processes and their open handles. There is an excellent but less familiar utility in-built with Windows 7 and higher, called Resource Monitor which provides complete details of running processes, their associated handles and associated modules (for example, DLL files).
1. To launch Resource Monitor, press WinKey + R, type resmon.exe and press ENTER.
2. Select the CPU tab, and expand Associated Handles by clicking on its title bar
3. Type a file name or part of the file name in the text box provided. This should list the processes which are currently accessing the file(s)
Bonus Tip! You can also type a registry key in the search field, which would cause Resource Monitor to show the registry handles with the corresponding process names.
View Associated Modules for a Process
There is another option wherein you can view the list of modules that are in use by a given process. Simply select one or more processes in the Processes section, and then expand the Associated Modules section to view the list of modules used by the selected processes.
Resource Monitor proves to be an useful tool to investigate processes and locked files, and can come in handy especially when you forget to bring your troubleshooting toolkit along when fixing a friend’s PC. «Associated Handles» and «Associated Modules» is a nice feature addition in Windows 7 and higher. You can also use Process Explorer to find this info. Check out Know which process has locked a file.
Incidentally, you may’ve also noticed that the «File in Use» dialog in Windows 7 and higher, displays the Process Name as well.
Related
Want to find which program is eating away your internet bandwidth? Resource Monitor can tell that too.
How to Identify the Process that has Locked a File in Windows
When you attempt to delete a file or folder which is in use by a process, the File In Use dialog appears showing the name of the program that has locked the file.
However, there are cases where the “File In Use” dialog doesn’t show the name of the process that has a lock on the file you’re trying to delete. In some cases, the dialog will show “the action can’t be completed because the file is open in another process“.
For investigating processes and locked files, Windows Sysinternals Process Explorer is probably the first option that comes to mind for most users. However, there are two built-in solutions to display the current open files list along with corresponding process names.
Find which process has locked a file using:
1. Resource Monitor
Resource Monitor (resmon.exe) is a built-in tool that has many useful features. With Resource Monitor, you can track current network and internet usage, view associated handles for locked files, as well as manage processes just as you’d using the Task Manager.
To find the process name that has a file locked, click the CPU tab, type the file name or part of it in the Associated Handles text box.
2. Process Explorer
Process Explorer needs no introduction. In Process Explorer, all you need to do is use the Find feature and type in the file name. This shows the process that’s accessing the file.
From the lower pane view, you can close the file handle if necessary.
You must run Process Explorer as administrator in order to manage processes which are running elevated. To elevate Process Explorer, click the File menu → Show Details for All Processes.
3. Handle from Windows Sysinternals
Handle is a utility from Microsoft Sysinternals that displays information about open handles for any process in the system. You can use it to see the programs that have a file open, or to see the object types and names of all the handles of a program. Handle is like a command-line version of Process Explorer.
Note: Handle v4.21 has a small bug where it always reports “No matching handles found” if the drive-letter is in uppercase. Hope Microsoft fixes it in the next update.
From an admin Command Prompt window, use the command-line syntax to find the process which is having the file open:
If the file name contains spaces, enclose it within double quotes.
Example:
(Mentioning the filename without the path may not necessarily work in every situation. It’s advisable to include the full path always.)
The output shows the process name, the process identifier, user name, the locked (target) file name with path.
Sysinternals Handle: Command-line arguments
-a | Dump all handle information. |
-l | Just show pagefile-backed section handles. |
-c | Closes the specified handle (interpreted as a hexadecimal number). You must specify the process by its PID.WARNING: Closing handles can cause application or system instability. |
-y | Don’t prompt for close handle confirmation. |
-s | Print count of each type of handle open. |
-u | Show the owning user name when searching for handles. |
-p | Dump handles belonging to process (partial name accepted). |
name | Search for handles to objects with (fragment accepted). |
-nobanner | Do not display the startup banner and copyright message. |
No arguments will dump all file references.
Add Sysinternals Handle to right-click menu
You can add Sysinternals Handle to the right-click menu for files to quickly find the program that has locked the file. To add it to the context menu, follow these steps:
- Download Handle from Microsoft Sysinternals site.
- Copy the files handle.exe & handle64.exe to a folder – e.g., d:\tools
- Copy the following lines of code to Notepad, and save the file as find_handle.vbs to a permanent location.
Note: The Sysinternals Handle.exe path is hard-coded as d:\tools\handle.exe in the above script. If the program is located on a different path, modify the path in the script accordingly. For 64-bit Windows, you can use either handle.exe or handle64.exe
To remove the Find Handle context menu entry, start the Registry Editor ( regedit.exe ) and delete the following key:
4. OpenFiles.exe — a built-in console tool
Another built-in tool we’re going to use is Openfiles.exe, a console tool that’s not new to Windows. It was originally introduced in 2000 as part of the Windows Resource Kit 2000/2003 tools. This utility was then included by default in Windows Vista and higher (including Windows 10). Openfiles displays the currently open files list from local or shared folders, along with the Handle ID and Process executable name. This tool also allows you to disconnect one or more files that are opened remotely from a shared folder.
Enable “Maintain Objects List” global flag for the First time
First, to enable tracking of local file handles, you need to turn on ‘maintain objects list’ flag by running the following command from admin Command Prompt.
You’ll see the following message:
INFO: The system global flag ‘maintain objects list’ is currently enabled.
You’ll need to run this command for the first time only. Then restart Windows for the change to take effect.
View open files and the corresponding process names
After restarting Windows, from an admin Command Prompt window, type:
This lists the File/Handle ID, Process Name and the list of files opened locally or opened remotely via local share points, in a table format.
To view the output in List or CSV formats, use the /query parameter.
To copy the output to clipboard, pipe the output to Clip.exe as below. Then paste the output in Notepad or any other editor of your choice.
For more information on copying Command Prompt output to clipboard or save the output to a file, check out the article How to Copy Command Prompt Output Text to Clipboard or Save to File?
To find if a particular file is being in use by a program (and to know which program), you may use the following command-line.
The above command lists all open files that contain the word “eiffel” in the file name. In this example, Word 2016 is currently having the lock over the file “The Eiffel Tower.docx” (ID 4576).
And “File In Use” dialog tells me the same thing.
Disconnect files opened remotely from shared folder.
To disconnect files opened from shared folder so that you can delete, rename the file or modify the contents, use the /disconnect parameter to cut connections to that file. Here are the command-line options.
Openfiles.exe perfectly does the job of listing all open files along with the process names, but it can’t forcibly kill processes. However, this excellent (but overlooked) built-in console tool can come in handy when you want to quickly find a process name that’s using a file, or to disconnect a file that’s being accessed through a shared folder by a network user — without depending on a third-party solution.
5. OpenedFilesView
OpenedFilesView from Nirsoft displays the list of all opened files on your system. For each opened file, additional information is displayed: handle value, read/write/delete access, file position, the process that opened the file, and more… Optionally, you can also close one or more opened files, or close the process that opened these files.