1

Is there a win32 api function which lists the programs that currently are accessing a file and locking it?

Ryan Glenn
  • 1,325
  • 4
  • 17
  • 30
  • I know it's possible, but it might not be as simple as a single API call. – Mark Ransom Jan 08 '22 at 05:11
  • This looks to be it: https://learn.microsoft.com/en-us/windows/win32/api/restartmanager/nf-restartmanager-rmgetlist – Ryan Glenn Jan 08 '22 at 05:21
  • 1
    [`FileProcessIdsUsingFileInformation`](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ne-wdm-_file_information_class) return this info. look https://stackoverflow.com/questions/47507578/winapi-get-the-process-which-has-specific-handle-of-a-file/47510579#47510579 – RbMm Jan 08 '22 at 05:23
  • But couldn't I simply run the restart manager manually, and add the files that may have a file opened and then run RmGetList()? – Ryan Glenn Jan 08 '22 at 06:02
  • you not need any restart manager, also internal this anyway call `NtQueryInformationFile` with `FileProcessIdsUsingFileInformation`. this is only way get this information – RbMm Jan 08 '22 at 06:54
  • 2
    Does this answer your question? [Winapi: Get the process which has specific handle of a file](https://stackoverflow.com/questions/47507578/winapi-get-the-process-which-has-specific-handle-of-a-file) – Simon Mourier Jan 08 '22 at 09:15
  • *"But couldn't I simply run the restart manager manually, and add the files that may have a file opened and then run RmGetList()?"* - Yes, you can (see [How do I find out which process has a file open?](https://devblogs.microsoft.com/oldnewthing/20120217-00/?p=8283)). – IInspectable Jan 08 '22 at 09:23

0 Answers0