doc/devdocs/modules/filelocksmith.md
Public overview - Microsoft Learn
File Locksmith is a utility in PowerToys that shows which processes are locking or using a specific file. This helps users identify what's preventing them from deleting, moving, or modifying files by revealing the processes that have handles to those files.
File Locksmith follows a similar architecture to the ImageResizer and NewPlus modules. It consists of:
Shell Extensions:
FileLocksmithExt - COM-based shell extension for Windows 10 and belowFileLocksmithContextMenu - Shell extension for Windows 11 context menuCore Components:
FileLocksmithLib - Handles IPC between shell extensions and UIFileLocksmithLibInterop - Core functionality for finding processes locking filesFileLocksmithUI - WinUI 3 user interface componentSettings Integration:
The module adds "Unlock with File Locksmith" to the context menu in File Explorer:
PowerToys.FileLocksmithUI.exeFileLocksmithLibInterop to scan for processes with handles to the fileThe core functionality to find processes locking files is implemented in FileLocksmith.cpp, which:
NtdllExtensions to iterate through file handlesThe UI is built with WinUI 3 and uses MVVM architecture:
To build and debug the File Locksmith module:
Build FileLocksmith module
FileLocksmith projectCreate certificate and import to Root (if you don't already have)
New-SelfSignedCertificate -Subject "CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" `
-KeyUsage DigitalSignature `
-Type CodeSigningCert `
-FriendlyName "PowerToys SelfCodeSigning" `
-CertStoreLocation "Cert:\CurrentUser\My"
$cert = Get-ChildItem -Path Cert:\CurrentUser\My | Where-Object { $_.FriendlyName -like "*PowerToys*" }
Export-Certificate -Cert $cert -FilePath "$env:TEMP\PowerToysCodeSigning.cer"
# under admin Terminal:
Import-Certificate -FilePath "$env:TEMP\PowerToysCodeSigning.cer" -CertStoreLocation Cert:\LocalMachine\Root
# get Thumbprint
Get-ChildItem -Path Cert:\CurrentUser\My | Where-Object { $_.FriendlyName -like "*PowerToys*" }
Sign the MSIX package
SignTool sign /fd SHA256 /sha1 <CERTIFICATE THUMBPRINT> "C:\Users\$env:USERNAME\source\repos\PowerToys\x64\Debug\WinUI3Apps\FileLocksmithContextMenuPackage.msix"
SignTool might be not in your PATH, so you may need to specify the full path to it, e.g., C:\Program Files (x86)\Windows Kits\10\bin\<version>\x64\signtool.exe.
commands example:
PS C:\Users\developer> New-SelfSignedCertificate -Subject "CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" `
>> -KeyUsage DigitalSignature `
>> -Type CodeSigningCert `
>> -FriendlyName "PowerToys SelfSigned" `
>> -CertStoreLocation "Cert:\CurrentUser\My"
PSParentPath: Microsoft.PowerShell.Security\Certificate::CurrentUser\My
Thumbprint Subject EnhancedKeyUsageList
---------- ------- --------------------
1AA018C2B06B60EAFEE452ADE403306F39058FF5 CN=Microsoft Corpor… Code Signing
PS C:\Users\developer> Get-ChildItem -Path Cert:\CurrentUser\My | Where-Object { $_.FriendlyName -like "*PowerToys*" }
PSParentPath: Microsoft.PowerShell.Security\Certificate::CurrentUser\My
Thumbprint Subject EnhancedKeyUsageList
---------- ------- --------------------
1AA018C2B06B60EAFEE452ADE403306F39058FF5 CN=Microsoft Corpor… Code Signing
PS C:\Users\developer> & "C:\Program Files (x86)\Windows Kits\10\bin\10.0.26100.0\x64\signtool.exe" sign /fd SHA256 /sha1 1AA018C2B06B60EAFEE452ADE403306F39058FF5 "%REPO_PATH%\PowerToys\x64\Debug\WinUI3Apps\FileLocksmithContextMenuPackage.msix"
Done Adding Additional Store
Successfully signed: C:\Users\developer\Develop\GitHub\PowerToys\x64\Debug\WinUI3Apps\FileLocksmithContextMenuPackage.msix
Remove old version
Get-AppxPackage -Name Microsoft.PowerToys.FileLocksmithContextMenu*
Remove-AppxPackage Microsoft.PowerToys.FileLocksmithContextMenu_1.0.0.0_neutral__8wekyb3d8bbwe
Install new signed MSIX
Add-AppxPackage -Path "%REPO_PATH%\PowerToys\x64\Debug\WinUI3Apps\FileLocksmithContextMenuPackage.msix" -ExternalLocation "%REPO_PATH%\PowerToys\x64\Debug\WinUI3Apps"
Restart Explorer
Debug Process
dllhost.exe with FileLocksmith Title to debug the shell extension
PowerToys.FileLocksmithUI.exe to debug the UIAlternative Debugging Method
FileLocksmithUI as startup project directly in Visual Studio, which will launch the UI without needing to go through the shell extension. This is useful for debugging the UI logic without the shell extension overhead.There is an open PR to change the IPC mechanism from file-based to pipe-based, but it has blockers:
File Locksmith integrates with the PowerToys settings through: