When managing shared folders across local networks or collaborating on documents hosted on Windows workstations, users frequently encounter the error: “The action cannot be completed because the file is open in another program”. Tracking down which network user, IP address, or background process holds an active lock on a shared file usually requires navigating deep into Computer Management MMC snap-ins. Windows 11 includes openfiles.exe, a dedicated administrative command-line utility designed to query active file handles, audit remote SMB connections, and forcefully release file locks directly from the terminal.
Launching Administrative Terminal Console
Auditing file locks and terminating SMB sessions requires full local administrator rights:
- Press Win + X and choose Terminal (Admin) or PowerShell (Admin).
- Accept the User Account Control (UAC) prompt to proceed.
Querying Active Shared File Locks Across the Network
By default, openfiles /query queries files opened remotely across the network via Server Message Block (SMB) file shares:
openfiles /query
The command outputs a structured table detailing active file locks:
- ID: Unique integer handle identifier assigned to the open connection.
- Accessed By: Username or remote account accessing the shared resource.
- Type: Connection protocol (typically
Windowsfor SMB shares). - Open File (Path): Absolute local filesystem path to the locked file or folder.
To format the output as a clean comma-separated list or readable table for automated scripting, pass the /fo flag:
openfiles /query /fo table /v
openfiles /query /fo csv > C:\Reports\ActiveFileLocks.csv
The /v (verbose) switch reveals additional attributes, including open modes (Read, Write, or Read/Write) and locking status.
Disconnecting and Releasing File Locks by ID
When a remote user leaves an application open overnight or a frozen network session prevents other users from editing a shared spreadsheet, you can terminate the connection using the /disconnect subcommand:
openfiles /disconnect /id 28
Windows immediately severs the SMB handle, releasing the file lock so other users can open, modify, or move the resource.
Disconnecting File Locks by User or Open File Path
If a specific user is holding locks across dozens of files simultaneously, disconnect all locks belonging to that user account in a single operation:
openfiles /disconnect /a "JohnDoe"
To disconnect all open handles attached to a specific file or folder path across the network:
openfiles /disconnect /op "C:\SharedDocs\Q4_Financials.xlsx"
Enabling the Local Maintain Objects List Flag
While network shared file auditing works out of the box, querying locally locked files held by local background processes requires enabling the global kernel object tracking flag. Note that enabling local tracking introduces slight CPU performance overhead.
To enable local open file auditing:
openfiles /local on
Windows prompts you to reboot the machine for the kernel object tracker to initialize. After rebooting, executing openfiles /local displays all local process file handles, functioning similarly to Sysinternals handle.exe.
To disable local tracking after troubleshooting is complete:
openfiles /local off
Targeting Remote Windows Servers and Workstations
System administrators can query file locks on remote Windows machines across the domain without establishing an interactive RDP session by passing the /s parameter:
openfiles /query /s FILESERVER-01 /fo table
Essential openfiles Parameter Reference
| Command Syntax | Operational Function |
|---|---|
openfiles /query |
Lists all active file locks opened remotely across SMB shares. |
openfiles /query /v |
Displays verbose details including lock mode and permissions. |
openfiles /disconnect /id [ID] |
Closes an open file lock matching the specific numeric handle ID. |
openfiles /disconnect /a [User] |
Terminates all open file connections owned by a named user. |
openfiles /disconnect /op [Path] |
Releases all locks attached to a specific file or folder path. |
openfiles /local on |
Enables kernel object tracking for local process handle auditing. |