2

I need to be able to check who has a file open using C#. I found a few people asked this question before but they were all a long time ago with the latest being in 2012. I was wondering if, in the last 5 years, has Microsoft added this ability to .net or maybe someone came out with a nuget package that is capable.

Here is the latest answer I found

Community
  • 1
  • 1
djblois
  • 963
  • 1
  • 17
  • 52

2 Answers2

1

You can use windows internal function NTQuerySystemInformation with undocumented parameter SystemHandleInformation for it. I don't know about c# implementation, but I know delphy code for it, and vb6 code. Check this links, it will help you to make your c# implementation.

Delphi - get what files are opened by an application

https://forum.sysinternals.com/topic14546.html

Community
  • 1
  • 1
Mihail Kuznesov
  • 555
  • 2
  • 13
  • Here is the [pInvoke signature](http://www.pinvoke.net/default.aspx/ntdll.ntquerysysteminformation) for using that method in .NET. – Bradley Uffner Mar 28 '17 at 17:15
0

As far as I know, the standard library still does not have suitable functions for this. There is a popular question about this: https://stackoverflow.com/a/937558/5665527.

Also, if you want to know who opened the file remotely - net file function may be useful (which is accessible via cmd). I believe that there are similar WinAPI functions on MSDN that could be implemented in a similar way.

Community
  • 1
  • 1
MrPickman
  • 44
  • 3