cklutz / LockCheck

Uses platform APIs to find processes locking one or multiple files (Windows - Restart Manager or NTDLL)
MIT License
106 stars 20 forks source link

Check against working directories of all running processes #6

Open KirillOsenkov opened 2 years ago

KirillOsenkov commented 2 years ago

I've learned an interesting thing today:

you can't delete a directory which is a working directory of some running process on Windows. So if you get Access Denied when trying to delete a directory, check for a running process whose current directory is it.

We should consider extending LockCheck to iterate over running processes and check if there's a process whose current directory is the one we're asking about (or a subdirectory thereof).

KirillOsenkov commented 2 years ago

Let me know if you'd like a PR for this.

KirillOsenkov commented 1 year ago

Here's a sample of getting the current directory for any given process: https://github.com/KirillOsenkov/Misc/blob/cf1b6ece2be91459bb301f65eac5b10e2f398562/GetProcessCurrentDirectory.cs#L16