PC Review


Reply
Thread Tools Rate Thread

How to detect if a file is accessed (Opened)

 
 
Martin Arvidsson, Visual Systems AB
Guest
Posts: n/a
 
      23rd Jan 2007
Hi!

I want to create an event that is fiered when a file is accessed (Opened).

What i want to do is monitor a directory and subdirectory if files are
opened.

I have tried to use the FileSystemWatcher. But it didn't work as i expected.
I cant get it to fire an event when a file is accessed.

Any hints? Ideas, Links?

Regards
Martin


 
Reply With Quote
 
 
 
 
PhilipDaniels@foo.com
Guest
Posts: n/a
 
      23rd Jan 2007
On Tue, 23 Jan 2007 12:39:45 +0100, "Martin Arvidsson, Visual Systems
AB" <(E-Mail Removed)> wrote:

>Hi!
>
>I want to create an event that is fiered when a file is accessed (Opened).
>
>What i want to do is monitor a directory and subdirectory if files are
>opened.
>
>I have tried to use the FileSystemWatcher. But it didn't work as i expected.
>I cant get it to fire an event when a file is accessed.
>
>Any hints? Ideas, Links?
>
>Regards
>Martin
>


It can be done (in Windows at least) - check out the tool FileMon from
www.sysinternals.com for an example. I suspect you will need interop
to the Windows API. Sorry I can't point you to which API call you will
need.



--
Philip Daniels
 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      23rd Jan 2007
Hi,

Did you try NotifyFilters.LastAccess ?

If not good enough for you , then you will have to p/invoke some win api
(which should not be nice)


--
Ignacio Machin
machin AT laceupsolutions com


"Martin Arvidsson, Visual Systems AB" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
| Hi!
|
| I want to create an event that is fiered when a file is accessed (Opened).
|
| What i want to do is monitor a directory and subdirectory if files are
| opened.
|
| I have tried to use the FileSystemWatcher. But it didn't work as i
expected.
| I cant get it to fire an event when a file is accessed.
|
| Any hints? Ideas, Links?
|
| Regards
| Martin
|
|


 
Reply With Quote
 
Martin Arvidsson, Visual Systems AB
Guest
Posts: n/a
 
      23rd Jan 2007
Hi!

Yes, but no events are triggered when i open the file.

Do i do something wrong?

Regards
Martin

"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.com> skrev i
meddelandet news:(E-Mail Removed)...
> Hi,
>
> Did you try NotifyFilters.LastAccess ?
>
> If not good enough for you , then you will have to p/invoke some win api
> (which should not be nice)
>
>
> --
> Ignacio Machin
> machin AT laceupsolutions com
>
>
> "Martin Arvidsson, Visual Systems AB" <(E-Mail Removed)> wrote in
> message news:(E-Mail Removed)...
> | Hi!
> |
> | I want to create an event that is fiered when a file is accessed
> (Opened).
> |
> | What i want to do is monitor a directory and subdirectory if files are
> | opened.
> |
> | I have tried to use the FileSystemWatcher. But it didn't work as i
> expected.
> | I cant get it to fire an event when a file is accessed.
> |
> | Any hints? Ideas, Links?
> |
> | Regards
> | Martin
> |
> |
>
>



 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      23rd Jan 2007
"Martin Arvidsson, Visual Systems AB" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi!
>
> I want to create an event that is fiered when a file is accessed (Opened).
>
> What i want to do is monitor a directory and subdirectory if files are opened.
>
> I have tried to use the FileSystemWatcher. But it didn't work as i expected.
> I cant get it to fire an event when a file is accessed.
>
> Any hints? Ideas, Links?


This can't be done from user space, you'll have to write a FS filter driver, something which
is not possible using managed code.
Not sure why you need this though, mind to tell us?

Willy.

 
Reply With Quote
 
Martin Arvidsson, Visual Systems AB
Guest
Posts: n/a
 
      23rd Jan 2007
I am creating a simple RCS.

The thing is we have a 4G development software and it's a bit odd. The new
version simply
locks the development area when a user opens a workspace.

What i want to do is have a master on the server, each developer should have
a local copy.

When a user opens a file for editing on a local computer, it will check what
file is opened. Check against a list. If the file is opened, it will tell
the user that the file is currentlu beeing edited by another user. And a
little more functions which i dont have time to describe right now...

/Martin

"Willy Denoyette [MVP]" <(E-Mail Removed)> skrev i meddelandet
news:(E-Mail Removed)...
> "Martin Arvidsson, Visual Systems AB" <(E-Mail Removed)> wrote in
> message news:(E-Mail Removed)...
>> Hi!
>>
>> I want to create an event that is fiered when a file is accessed
>> (Opened).
>>
>> What i want to do is monitor a directory and subdirectory if files are
>> opened.
>>
>> I have tried to use the FileSystemWatcher. But it didn't work as i
>> expected.
>> I cant get it to fire an event when a file is accessed.
>>
>> Any hints? Ideas, Links?

>
> This can't be done from user space, you'll have to write a FS filter
> driver, something which is not possible using managed code.
> Not sure why you need this though, mind to tell us?
>
> Willy.
>



 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      23rd Jan 2007

"Martin Arvidsson, Visual Systems AB" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
| Hi!
|
| Yes, but no events are triggered when i open the file.
|
| Do i do something wrong?

Post your code, not only you need to correctly set the NotifyEvents but also
you need to assign the correct event handler.

Are you activating the FileSystemWatcher?


--
Ignacio Machin
machin AT laceupsolutions com


 
Reply With Quote
 
Martin Arvidsson, Visual Systems AB
Guest
Posts: n/a
 
      23rd Jan 2007
Hi!

Yes the filewatcher is enabled...

I have assigned every event, Change, Create. etc

But it will not simply raise

If i add all the filters i can se when its changed, created etc. But any
events on when the file is opened is not done.

/Martin


"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.com> skrev i
meddelandet news:(E-Mail Removed)...
>
> "Martin Arvidsson, Visual Systems AB" <(E-Mail Removed)> wrote in
> message news:(E-Mail Removed)...
> | Hi!
> |
> | Yes, but no events are triggered when i open the file.
> |
> | Do i do something wrong?
>
> Post your code, not only you need to correctly set the NotifyEvents but
> also
> you need to assign the correct event handler.
>
> Are you activating the FileSystemWatcher?
>
>
> --
> Ignacio Machin
> machin AT laceupsolutions com
>
>



 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      23rd Jan 2007
Hi,



"Martin Arvidsson, Visual Systems AB" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
| Hi!
|
|
| I have assigned every event, Change, Create. etc
|
| But it will not simply raise
|
| If i add all the filters i can se when its changed, created etc. But any
| events on when the file is opened is not done.
|
| /Martin
|
|
| "Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.com> skrev i
| meddelandet news:(E-Mail Removed)...
| >
| > "Martin Arvidsson, Visual Systems AB" <(E-Mail Removed)> wrote
in
| > message news:(E-Mail Removed)...
| > | Hi!
| > |
| > | Yes, but no events are triggered when i open the file.
| > |
| > | Do i do something wrong?
| >
| > Post your code, not only you need to correctly set the NotifyEvents but
| > also
| > you need to assign the correct event handler.
| >
| > Are you activating the FileSystemWatcher?
| >
| >
| > --
| > Ignacio Machin
| > machin AT laceupsolutions com
| >
| >
|
|


 
Reply With Quote
 
Ignacio Machin \( .NET/ C# MVP \)
Guest
Posts: n/a
 
      23rd Jan 2007
Hi,

"Martin Arvidsson, Visual Systems AB" <(E-Mail Removed)> wrote in
message news:(E-Mail Removed)...
| Hi!
|
| Yes the filewatcher is enabled...
|
| I have assigned every event, Change, Create. etc
|
| But it will not simply raise
|
| If i add all the filters i can se when its changed, created etc. But any
| events on when the file is opened is not done.

Sorry, the other post went away before I finished writting it

So in that is the case you may have to deal with P/invoke.

Even so, I would advise you to first try to explorer WMI, maybe you have a
way of doing it using WMI


--
Ignacio Machin
machin AT laceupsolutions com


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to detect closing a file opened by a Process? Henk van Winkoop Microsoft C# .NET 1 25th Apr 2007 05:22 PM
Floppy drive (A:) is accessed when Windows Explorer is opened Rich Windows XP Help 4 17th Apr 2007 02:55 PM
"The file cannont be opened because your virus scanner has detect. =?Utf-8?B?S0NvdHRlZW4=?= Microsoft Excel Crashes 1 20th Nov 2006 10:25 PM
How to detect someone has accessed the C$ on the machine Rembrandt Microsoft Windows 2000 Networking 3 4th May 2005 11:33 PM
newbie: Detect if a file is already opened =?Utf-8?B?U2FtIEpvaG5zb24=?= Microsoft Dot NET 3 25th Feb 2004 07:40 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:43 AM.