FileSystemWatcher + Monitor Reads/Opens

J

James

Hey all,

I am looking to use FileSystemWatcher to monitor file access, deletion,
creation, and modification.

However, I also want to monitor when any user opens / reads this file?
Is this possible?

Thanks in advance.

-- James
 
K

Kevin Spencer

You should be able to use NotifyFilters.LastAccess to do this.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
K

Kevin Spencer

That would be the "Changed" event..

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
J

James

Perhaps I am doing this wrong but CHANGED does not raise an event when
the file is opened.
 
K

Kevin Spencer

Hi James,

Without seeing your code, I can't tell you what's going wrong. However, the
following MSDN article has a sample that illustrates how to use the
notifyFilters Enumeration to specify what sort of changes to watch for. You
will note that "LastAccess" is included in the sample:
http://msdn.microsoft.com/library/d...guringfilesystemwatchercomponentinstances.asp

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
K

Kevin Spencer

Hi James,

Interesting. Aside from seeing your actual code, I'm at a loss. I have never
tried to use that particular filter. I do know from my research that the
LastAccess attribute is not immediately updated on the disk by NTFS, but
stored in memory. Perhaps that is the root of the issue. Have you tried
waiting?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
J

James

Perhaps we are barking down the wrong path here, getting help up on
some functionallity that is just not meant to be. Is there a better
way of accomplishing my task? Simply put, I want to monitor ALL file
activity on a system (like FileMon from sysinternals). I can from
there filter out what I need and react accordingly . However, I am
trying to accomplish this without writing a driver (which is how i
believe filemon works).

Any suggestions?
 
K

Kevin Spencer

Thanks James. I didn't realize that the "asp" got dropped somehow between my
copying and pasting!

--

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
J

James

The method(s) seemed promising however i still cannot track the opening
of a specific file.

I.E. when user X opens file Y i want to know about it immediately.

Suggestions?
 
K

Kevin Spencer

Hi James,

I think I mentioned that I had not used the LastAccessed filter before. I
may be misunderstanding its use. It only seems to be mentioned in connection
with other types of actions that change a file, such as renaming, changing
its contents, etc. In any case, I'm not at all sure any more that you can
use this to determine whether or not a file has been read only, without
changing it.

I'm sure that somewhere there is an event that happens which you can
capture, but I have scoured the MSDN Library without success trying to find
it.

How about we back up a bit. What exactly is the situation here? Perhaps
there is a parameter of your requirements that can be leveraged in another
way.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.
 
J

James

Simply stated, I want to know (by being signalled, no polling as its
way to resource intensive) that a file of my selection has been
opened/read, modified in some way, or deleted. The second two are
easily done, the first one is not very easy at all. From what I've
read i think I'm doomed to driver territory, writing an upper filter
driver for the file system.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top