Open files

What is the best and simplest way to detect the process currently opening a given file?

Regards

marius

for a manual process, I use Process Explorer. https://docs.microsoft.com/en-us/sysinternals/downloads/process-explorer

To do it automated with PowerShell, um um need someone smarter than me.

You could use handle.exe

with PowerShell, something like below.

# Say I've opened a file named test.log
Get-CimInstance -ClassName Win32_Process -Filter "CommandLine like '%test.log%'"

# This filter is actually applied on CommandLine property of below output
Get-CimInstance -ClassName Win32_Process | Select-Object -First 1 | Format-List *