Question

We currently have a problem with too many users trying to access a single file through a legacy program that uses filelocks.

I am trying to work out if it is feasible to write a dotnet program that will run on the server and monitor this specific file (flat file database). Whenever a client tries to access this file and it is locked by another user - I want to send them a message telling them who is accessing the file so they can annoy that person rather than me.

When I open compmgmt.msc I can see the file, the filelock and the user locking it so I know this information is accessible. However I can't seem to find a dotnet class that can get this information (#locks, user that has locked it).

Does anybody know of a class that can help me here?

Was it helpful?

Solution

The underlying winapi function is NetFileEnum(). You'll have to pinvoke it.

OTHER TIPS

You can probably access these informations through WMI (Windows Management Instrumentation): http://msdn.microsoft.com/en-us/library/windows/desktop/aa394582%28v=vs.85%29.aspx

This could be a good starting point: http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/19b88200-3dfd-4042-b16a-1f514dd5e1f9

Also, try to get the informations you are looking for before start coding using WMI Explorer: http://www.ks-soft.net/hostmon.eng/wmi/index.htm

This could also help: select * from cim_datafile where name='d:\file.txt'

Please note the use of double slash "\"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top