How to list processes that lock drive

For testing, I have a USB flash drive mounted on E:. I opened E:\foo.png using IrfanView. That prevents the drive from being ejected. The 3rd party tool USB Safely Remove correctly identifies IrfanView as the blocking process:

Using PowerShell, how do I list all processes preventing a drive from being ejected?

I had a look at Sysinternals’ Handle. It lists a ton of processes, but exactly not the one that is locking E::

> handle.exe -nobanner E: | sls view

msedgewebview2.exe pid: 17320  type: Section        E2C: \Sessions\1\BaseNamedObjects\43a8HWNDInterface:10564
msedgewebview2.exe pid: 17320  type: Section        E30: \Sessions\1\BaseNamedObjects\43a8HWNDInterface:10564

You may use the command line version of the tool?

1 Like

I didn’t realize that there is a command line version. Thank you for pointing me to that! I was hoping to do without third party tools, but that should certainly do the trick. USB Safely Remove is a great tool.