How do I access running instances of Word?

L

ljh

For example, for Word I need to be able to do the following with .Net 2005
........

1) Detect any new instance of Word
2) Detect any files opened by that instance and the location of the file
opened (an event firing would be great)
3) Detect any files saved by that instance and the location that they were
saved to (an event firing would be great)
4) (ideally) Detect all mouse and key events performed in any instance of
Word

Although I am finding examples of Word automation, they all look to be
creating new instances and not querying existing Word instances.

Add-in examples using .Net 2005 woudl also be a great help.

ANY help you could give would be greatly appreciated.
 
C

Cindy Meister

I saw this yesterday, in the Addins group, but hesitated to respond...

There's nothing in the Word object model to "send a message" when a new
instance of Word is started, although an AutoExec macro in a template Addin
or the "StartupComplete" of a COM-Addin could possibly be used to trigger
something. Other than that, you'd need to use the Windows API to "watch" what
programs are run.

For opening, creating and saving documents you could sink the events
(DocumentOpen, DocumentNew DocumentBeforeSave) and use those procedures to
trigger/call something.

I'm afraid there are absolutely no exposure for mouse or keyboard events.
Word does provide an interface for assigning a keyprdss to any macro, but the
macro must be in a Word VBA project. In order to capture every key press,
you'd have to assign every key combination (using the KeyBindings collection)
to a macro.
 
L

ljh

Thanks for the response Cindy.

I was looking into using the FileSystemWatcher. That seemed like a really
simple solution until you realize that the FS events that are raised are
entirely dependent upon the system on which it is running. For example, on
a "clean system" (no antivirus etc.) Word may fire up to 4 events when
opening and closing a changed word file. On a system with real-time
antivirus capabilities there may be more. How many? Who knows? It depends
on the antivirus program in use and on other applications that may be
monitoring the file system.

FileSystemWatcher may be very useful in tightly controlled environments, but
it seems of limited use for mass distribution because of the inability to
determine which application (or process) is actually doing the changes to
the file.

I think that my solution will have to be a combination of old and new
technologies. I may use an add-in for saving the application at specific
intervals and COM interop to an old component that allowed me to do
system-wide key and mouse operation captures for the saving of the user's
Word session.

It's not as simple as I would have liked, but it should get the job done.

Thanks again!
 

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