3

When you try to delete a file in Windows Explorer, and that file is in use, it brings up a dialog saying File In Use and it proceeds to give you the file name that has the file open.

For example,

Example

I've seen hacks involving kernel drivers, but if Windows Explorer can do it, then there must be an easier way.

What is the best and easiest way to get this information?

Community
  • 1
  • 1
AlexPi
  • 539
  • 5
  • 16
  • Related: http://stackoverflow.com/questions/1990535/win32-files-locked-for-reading-how-to-find-out-whos-locking-them – Jim Mischel May 16 '12 at 02:51
  • 1
    Use the Restart Manager. [Sample code here](http://blogs.msdn.com/b/oldnewthing/archive/2012/02/17/10268840.aspx). – Raymond Chen May 16 '12 at 05:05
  • possible duplicate of [Delphi - finding the process that is accessing a file from my program](http://stackoverflow.com/questions/8726906/delphi-finding-the-process-that-is-accessing-a-file-from-my-program) – David Heffernan Feb 11 '13 at 17:30

1 Answers1

6

Starting with windows vista you can use the IFileIsInUse interface, if you want support older versions of windows you can use the NtQuerySystemInformation, NtQueryInformationFile and NtQueryObject WinApi functions, for more infomation about this topic check my answer on this question.

Community
  • 1
  • 1
RRUZ
  • 134,889
  • 20
  • 356
  • 483