Using C# how can I get information about who has a file open? User name and machine name would be sufficient.
In case it matters I have Windows workstations accessing files on a Linux file server via Samba. I need this information in a program running on the workstations.
Open the file using the "fopen" function and assign the "file" to the variable. Check to make sure the file was successfully opened by checking to see if the variable == NULL. If it does, an error has occured.
The fopen() method in C is a library function that is used to open a file to perform various operations which include reading, writing etc.
Using fopen() function You can use fopen() function to open given file in read mode. If it returns NULL then file does not exists otherwise exists on disk. Testing file existence using fopen() is not reliable. fopen() fails if you don't have read/write/execute permissions on file.
The core .NET libraries do not have any means to do this.
And if I understand you correctly, you want to know from Windows workstation A who has files open on the Linux file share and some of those users with open file might be origination from other windows boxes, if that is the case then you will need to have a service on the Linux side which you can query to provide that back to your windows work station.
On the local machine this can be achieved, but at the very least your will need to interop to OS APIs like NtQueryInformationFile and NtQueryObject (both not officially documented) amongst others. Tools like process monitor dynamically install a device driver to achieve the level of inspection that they do and that will only tell you which local file handles are open by which user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With