How 7-Zip Handles Files Locked by Another Process
When attempting to open, compress, or modify archive files locked by another running process, 7-Zip adheres strictly to standard operating system file-sharing permissions, resulting in specific behaviors ranging from read-only access to sharing violation errors. This article explains how 7-Zip interacts with locked files during compression and extraction, the mechanics behind its file-access errors, and the built-in features available to work around locked-file restrictions.
Reading and Extracting Locked Archives
If a running process has opened an existing archive file, 7-Zip's ability to read or extract it depends entirely on the file-sharing flags granted by the locking application:
- Shared Read Access: If the locking process allows shared reading (e.g., another program is simply reading data without an exclusive lock), 7-Zip can successfully open, browse, and extract the contents of the archive.
- Exclusive Locks: If another application holds an exclusive lock (common during active file downloads, database operations, or dedicated stream writes), Windows denies access to other processes. In this scenario, 7-Zip fails immediately and generates an error stating that the file cannot be accessed because it is being used by another process.
Modifying and Updating Locked Archives
Modifying an existing archive (adding, updating, or deleting files within it) requires exclusive write access.
When you modify an archive in 7-Zip:
- 7-Zip creates a temporary archive file containing the modified data.
- Once the operation finishes, it attempts to overwrite the original archive file.
- If the target archive is actively locked by another process, the overwrite operation fails. 7-Zip will throw an error, abort the replacement, and retain the temporary file so that no compressed data is corrupted or lost.
Compressing
Files Locked by Other Processes (-ssw Switch)
A common issue occurs when 7-Zip tries to add external files to an archive while those source files are currently open in other programs (such as log files or active documents).
By default, 7-Zip requires that source files not be in the process of being written to. If a file is opened with shared write permissions by another program, 7-Zip might still fail unless explicitly configured:
- The
-sswCommand-Line Switch: The-sswflag instructs 7-Zip to compress files that are currently opened by other processes with write access. - GUI Setting: In the 7-Zip graphical interface, you
can enable this behavior by passing
-sswin the Parameters field within the "Add to Archive" dialog. - Limitation: The
-sswswitch only works if the locking application opened the file allowing shared write permissions (FILE_SHARE_WRITE). If the file is locked with exclusive access (FILE_SHARE_NONE),-sswcannot bypass the lock.
Volume Shadow Copy (VSS) Limitations
7-Zip does not natively integrate with the Windows Volume Shadow Copy
Service (VSS). Consequently, it cannot natively bypass kernel-level or
completely exclusive file locks (such as active system registry hives,
Outlook .pst files, or running virtual disk images). To
back up or compress files locked exclusively at the system level, users
must either close the locking process or rely on third-party scripts
that generate a VSS snapshot before pointing 7-Zip to the snapshot
volume.