System.IO.FileSystemWatcher class and user identity

  • Thread starter Thread starter benjsoft
  • Start date Start date
B

benjsoft

hello, i would like to seek your expertise on how to determine the
identity of the user (remote/local) that modified/created/deleted a
file?

i'm currenty developing a simple windows form app using C# that
monitors any changes in my filesystem using the FileSystemWatcher
class of System.IO namespace. My only problem now is how to retrieve
the user (remote/local) that performs something on that file.

Thanks!
 
First off, you'll need to devise some way of determining whether the changes
to a file were made locally or remotely. WMI is probably your best bet for
gathering information about what remote users have files open. I haven't
had a chance to really try it myself yet, but it looks like you can use WMI
classes to gather the information you need. The Win32_ServerConnection
class looks promising and should provide a good starting point even if it
doesn't do exactly what you need. If you're not familiar with WMI, the is a
decent example provided in the VS.NET SDK examples under "<Visual Studio
Install Directory>\SDK\v1.1\Samples\Technologies\Interop\Applications\WMI"

For locally made changes, finding the user is as easy:

// I'm sure there may be other ways to go about this as well.
string user = Environment.GetEnvironmentVariable("USERNAME");

Hope this helps!
DL
 
Back
Top