Table of Contents

Windows - Find what process is holding a file open

Sharing violation errors.


Use the Resource Monitor

WARNING: Be very careful with closing handles!

It's even more dangerous than you'd think, because of handle recycling - if you close the file handle, and the program opens something else, that original file handle you closed may be reused for that “something else.”

And now guess what happens if the program continues, thinking it is working on the file (whose handle you closed), when in fact that file handle is now pointing to something else.


Use Sysinternals

To find a specific file, navigate to Find → Find Handle or DLL….

Type in part of the path to the file.

The list of processes will appear below.


If you prefer command line, Sysinternals suite includes command line tool Handle, that lists open handles.

Examples:

c:\Program Files\SysinternalsSuite>handle.exe |findstr /i "e:\" (finds all files opened from drive e:\"

c:\Program Files\SysinternalsSuite>handle.exe |findstr /i "file-or-path-in-question"