0

I want to execute few task based open targeted file's OPEN event. For example, I am watching Sample.docx & whenever user will go for OPEN it, few subsequent task will be performed based upon it's OPEN action.

I have searched on internet & find out few solution but that are based upon file's MODIFICATION & DELETION operation. none of them shows based upon OPEN action which is actually I am looking for.

Any hint/suggestion would help me. Thanks.

Vishal Gajera
  • 4,137
  • 5
  • 28
  • 55

2 Answers2

0

That is an operating-system specific functionality and is not something Java comes with out of the box. If you are on Windows you would use a FileSystemWatcher which exists in .NET, but if you need it in Java you would have to create native bindings if there isn't a library that already exists. Chances are this does not exist as not many people would have a valid use-case to do this and I don't think security people would be happy to see this either.

Derrops
  • 7,651
  • 5
  • 30
  • 60
0

You could I suppose, in a specific thread, regularly poll currently running processes to see if the file name is contained within a process title.

As for .docx files for example, WORD would have this as its process title:

Sample.docx - Microsoft Word

You would need to utilize a JNA method named getAllWindowNames() to acquire a list of Window Names. This method works quite well. When Sample.docx is detected within the acquired list then start whatever file or files you like.

Keep in mind however, your Java application would need to always be running in the background and because of file association (as mentioned to you in a previous post) this technique would run the files you have associated with Sample.docx regardless of how the file was run (from a double-click in Windows Explorer, a shortcut on Desktop, opened from MS WORD itself, etc).

I have actually created a small demo application that does exactly what you are trying to accomplish however it is too large to post here. There is no tutorial that I know of for this sort of thing, it's just a matter of doing it....that is if the concept appeals to you.

Yes!...most people would not want this sort of thing dancing around on their System(s).

DevilsHnd - 退職した
  • 8,739
  • 2
  • 19
  • 22