Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

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

March 29, 2021 Windows 10Windows Server 2016

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.

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

Related Reading

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

How to Use Ansible to Manage Windows Machines

September 25, 2023

Installing Language Pack in Windows 10/11 with PowerShell

September 15, 2023

How to View and Change BIOS (UEFI) Settings...

September 13, 2023

6 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

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

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
  • Updating List of Trusted Root Certificates in Windows
  • How to Create a Wi-Fi Hotspot on your Windows PC
  • How to Sign an Unsigned Device Driver in Windows
  • How to Download APPX File from Microsoft Store for Offline Installation?
Footer Logo

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


Back To Top