Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / Windows 10 / How to Unlock a File Locked by Any Process or SYSTEM?

March 29, 2021

How to Unlock a File Locked by Any Process or SYSTEM?

Sometimes when you try to delete, rename or move a file in Windows, you may see a message that the file is busy/locked/used by another process. Usually the name of the program that keeps the file open is shown right in the File Explorer message window. To unlock the file, it is enough just to close the program. However, it may occur that a file or a library is used by an unknown or system process. Then it is harder to unlock it.

Many apps open files in the exclusive mode. At the same time, the file is locked by a file system preventing input-output operations from other apps and process. If you close the app, the file lock is released.

A file lock message may be different. For example, the following screenshot shows the file type and the app it is associated with:

File/Folder in Use. The action can’t be completed because the file is open in another program. Close the folder or file and try again.

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

Then you can easily understand which app has locked the file and close it.

However, sometimes you may see a more interesting message that a file is used by an unknown or Windows system process. It may be either a Windows process or other processes working with the System privileges, like an antivirus app, a backup agent, an MSSQL database, etc.:

The action can’t be completed because the file is open in SYSTEM.
Close the file and try again.

The action can’t be completed because the file is open in SYSTEM

Let’s try to find out what program, service or Windows system process is using a file, how to unlock the file and whether it may be released without closing the parent process.

If you cannot delete a folder in a shared network folder, the problem is likely to be related to thumbs.db containing thumbnail cache of files in the folder or the file is opened (locked) by another user on your SMB file server.

The easiest way to unlock the file is to end the process that has locked it. But it is not always possible, especially on the servers.

To find a process that has locked a file, it is often recommended to use the Unlocker tool. I don’t use Unlocker since it doesn’t provide a detailed information about a process or a chain of processes having locked a file. Neither you can unlock a file used by a process — you have to kill an app completely.

Also, it is a third-party tool, and you should be very attentive when you install it, because it suggests to install a whole bundle of programs you don’t need.

When a process in Windows opens a file, a file descriptor (handle) is assigned to the input/output stream. The process and its child processes access the file using the handler. Using Windows API, you can send a signal to your file system to free the file handle and unlock the file.

If you force file handles to close, it may result in an unstable work of your app or computer. If you are not sure what may happen after you close file handle of an app, do not do it on a production server unless you have tested it in advance.

How to Unlock a File Using Process Explorer?

ProcessExplorer is a free tool from the Sysinternals kit you can download from Microsoft website (https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer). Let’s try to find a process that has locked a file and free the file by resetting the file handle of the process.

  1. You don’t need to install ProcessExplorer: just download, extract and run procexp.exe as administrator;
  2. Select Find -> Find Handle or DLL (or press Ctrl-F); process explorer - find handle or dll
  3. Specify the file name you want to unlock and click Search;
  4. Select the file you want. The process having opened the file will be highlighted in the process tree. Right-click it and select Kill Process Tree to end the process. However, you can try and close the file handle without ending the process. The file handle you looked for is automatically highlighted in the Process Explorer bottom panel. Right-click the handle and select Close handle. Confirm closing the file; release a file handle using process explorer
If the bottom panel with the list of open process handles is not displayed in your Process Explorer, enable the option View -> Lower Pane View -> Handles.

So you have closed the file handle without ending the parent process. Then you can remove or rename the file.

How to Release a File Handle Using the Handle Tool?

Handle is another command line tool from the Sysinternals (you can download it on Microsoft website: https://docs.microsoft.com/en-us/sysinternals/downloads/handle). It allows you to find a process having locked your file and release the lock by freeing the handle.

  1. Download and extract the Handle archive;
  2. Open the command prompt as an administrator and run the following command: handle64.exe > listproc.txt
  3. This command will save the list of open handles to a txt file. You can display handles for a directory the file you want to change is located in: Handle64.exe -a “C:\Program Files\App” or for the specific process: handle64.exe -p excel.exe
  4. Open listproc.txt in any text editor and find the line that contains the name of the locked file. Copy the file handle ID (in the hex format). Then go up to the section where the process that owns the handle is shown and write down its ID. It is most likely that a process run as system will have PID 4. get open file handle id using handle64.exe
    For some Windows system processes, handle.exe returns the following message: wininit.exe pid: 732 \<unable to open process>. It means that you cannot get any information about these system processes (even as administrator). To get file handles open by such processes, run the cmd.exe as System and try to get the list of handles again.
  5. Then get back to the command prompt and reset the file handle by its HandleID and ProcessID. The command has the following format: handl64e.exe -c HandleID -p ProcessID For example: handl64e.exe -c 18C -p 18800close file handle on windows 10
  6. The tool will prompt you to confirm closing of the file for the process. Confirm it by pressing y -> enter.

If the system reacts to the closing of the file correctly, you will unlock your file without ending the process or restarting your server/computer.

7 comments
7
Facebook Twitter Google + Pinterest
Windows 10Windows Server 2016
previous post
Configuring Password Policy in Active Directory Domain
next post
UAC: This App Has Been Blocked for Your Protection on Windows 10

Related Reading

How to Repair Windows Boot Manager, BCD and...

March 11, 2024

Fix: The Computer Restarted Unexpectedly or Encountered an...

May 16, 2024

PowerShell: Get Folder Size on Windows

April 2, 2024

Fixing “Winload.efi is Missing or Contains Errors” in...

March 16, 2024

How to Download Offline Installer (APPX/MSIX) for Microsoft...

March 12, 2024

Windows Doesn’t Automatically Assign Drive Letters

March 15, 2024

How to Clean Up System Volume Information Folder...

March 17, 2024

Protecting Remote Desktop (RDP) Host from Brute Force...

February 5, 2024

7 comments

OS March 29, 2021 - 8:35 am

I made an PowerShell function for unlocking locked files https://github.com/ztrhgf/useful_powershell_functions/blob/master/Unlock-File.ps1 based on this article. Thanks for inspiration 🙂

Reply
admin March 30, 2021 - 4:04 am

Nice and very fast work 🙂

Reply
Shlomi March 31, 2021 - 4:54 pm

Nice!! I download the script
thank you!

Reply
Shlomi March 31, 2021 - 4:54 pm

Amazing! thank you

Reply
Naven April 11, 2021 - 11:06 am

Good one without installing third party softwares..!!

Reply
Tistou January 20, 2022 - 3:31 pm

Don’t work with a file open by System pid : 4… 🙁

Reply
Nossy July 24, 2024 - 6:52 am

Is there any way to automate this so it automatically unlocks the file when its locked?

Reply

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Recent Posts

  • Map a Network Drive over SSH (SSHFS) in Windows

    May 13, 2025
  • Configure NTP Time Source for Active Directory Domain

    May 6, 2025
  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • How to Repair EFI/GPT Bootloader on Windows 10 or 11
  • How to Restore Deleted EFI System Partition in Windows
  • Network Computers are not Showing Up in Windows 10/11
  • Install and Manage Windows Updates with PowerShell (PSWindowsUpdate)
  • How to Download Offline Installer (APPX/MSIX) for Microsoft Store App
  • Updating List of Trusted Root Certificates in Windows
  • Fix: Windows Cannot Connect to a Shared Printer
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top