Open joshdoe opened 8 years ago
Its been requested a number of times before. I've never been able to find a windows api or working code for finding which processes are using a drive - the only solution I ever found involved installing a low level kernel driver which isn't portable. Ideally the code wouldnt require admin rights either.
Calling other programs is one possible solution but I'm not keen on it. USB Disk Eject is designed to be portable and many unlocker programs have to be installed in order to work. If it was going to call another application then I'd want to bundle it within the program and extract it and run it as required. For this - I'd need an unlocker that worked portably on Windows XP onwards and that had a licence that let me bundle it in. It'd also need to be a native executable - .net programs like Deadlock wouldn't be suitable as you cant always rely on a computer having the appropriate version of the .net framework installed.
Possible solution in this code, but looks like it might still require admin rights https://stackoverflow.com/questions/317071/how-do-i-find-out-which-process-is-locking-a-file-using-net/20623311#20623311
Might be possible to bundle this in and use it, depending on the licence http://www.nirsoft.net/utils/opened_files_view.html
I'm using the following unlocker tool, which specificly has a portable version: http://www.emptyloop.com/unlocker/
When a disk cannot be removed because a file is locked, currently a simple error message is shown. Other software like USB Safely Remove show which files are locked and which processes are locking them. If you can't add this functionality directly, you could call another application like DeadLock, which is also open source, or other tools like LockHunter.