Detect txt open file

  • Thread starter Thread starter Filipe Marcelino
  • Start date Start date
F

Filipe Marcelino

Hi,

I would like to know if it's possible to know if a text file is opened.

Thanks in advance for your help.

Regards,
Filipe Marcelino
 
I would like to know if it's possible to know if a text file is opened.Try to open it with exclusive rights.
If it fails then it is somehow locked and thus open.
 
Hi Olaf,

I already tried your sugestion but notepad doesn't open a text file in
exclusive mode.

What I actually want to do is to open a file (.doc, .txt, .xls, .vb,
..dwg, etc.) using System.Diagnostics.Process.Start(...) and specify
some kind of argument witch make notepad to open the specified file in
exclusive mode.
Is this possible?

Thanks.
 
Try to delete the file and see if it fails :)
No you cannot detect this. The thing you could possible do is to enumerate
over all open processed and its associated open handles but maybe this is
overkill and you'll need unmanaged code for that (at least I think so).
I bet you can solve your problem any other way.
What is the original problem you are facing?
 
IMO it doesn't have command line arguments doing that.

If notepad is launch from your app you could perhaps try something like
launching notepad, locking the file and releasing the file when notepad
ends, all this from your app...

Before doing such a thing you may want to explain what you are after in case
someone would have a better suggestion for what you are trying to do. What
do you want to make fails when the file is viewed ? Why ?
 
hi guys,

well, what i'm trying to do is to develop an application that will
monitorize the time spent unsing a file. To do so I need to know when a
file is opened and closed.

I already tried millions of ways to achieve that but unfortunetly none
of them have worked. I already concluded that notepad doesn't lock the
file in use (like word, excel, etc...) 'cause, one of the ways I've
tried was try to open a file in use by one of this applications in
exclusive mode from x to x seconds, and every time that action fails is
because the file is in use.

Patrice,

how can I know when an instance of notepad has terminated? I don't know
to do that.

The ideal plan is to create some kind of event-mechanism that fires an
event each time the SO open or closes as application or file...how can
I know this?

Regards,
Filipe Marcelino
 
if you use process.start you can subscribe to the "Exited" event which
occured when the process terminates.
 
You meant you would like to do that at the OS level for all files ?? You
could perhaps enable file access auditing and process the log but it looks
like a huge task for a not that valuable information (what if I just left
notepad opened all night ?).

Good luck.
 
Yes, at OS level for all files. Well, if you let the notepad open all
night I will not count that time 'cause you're idle...

Regards,
Filipe Marcelino
 
Back
Top