Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2005

Tip: Looking for answers? Try searching our database.

Word application hijacking

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jeroen ter Hofstede - 18 Oct 2005 12:52 GMT
[Posted to microsoft.public.word.programming and
microsoft.public.word.oleinterop. If there is a better place to post
this, please let me know.]

Our application uses and controls Word in order to have the user edit
documents of the application. To that end, it creates a Word object
using OLE, which starts up a WINWORD.EXE process.
It now appears that some other applications, most notably the Word
browser plug-in, will use that same WINWORD.EXE process to open their
documents. Furthermore, if the document opened in that application (the
browser, say) is active, the calls our application makes to Word are no
more handled correctly.

We've tried several workarounds to no avail (trying to activate Word
from within our app fails, starting a "decoy" word first may foil the
browser, but is also used when the user double-clicks a document and
can thus be closed, etc). What we actually would like to achieve is
that the WINWORD.EXE process that we start by instantiating a Word
application object via OLE cannot be hijacked by any other program.

Does anybody here know whether such a thing is possible?

Thanks in advance,
Jeroen
Tony Jollans - 24 Oct 2005 21:38 GMT
Not really much help but nobody else has chimed in so ...

Somebody will probably correct me but if you give control to the user
(which, of course you must if they are to edit the document) I don't think
there is any easy way you can stop other applications (or the user) from not
just using the instance but also, possibly, closing it.

You can keep a reference to your document so that you don't need to worry
which document is active - which may solve your immediate problem - but for
a more general solution you will need to have event code running in the Word
instance which reacts to documents being opened or closed; you could
possibly do this with a global template which you install when you first
start the Word instance (and uninstall when you end it). Although this might
solve _your_ problem, it could, of course, cause problems for other
applications which try to use the Word instance.

Normally the instance returned via GetObject is indeterminable in advance if
there are multiple instances of an application running so you don't gain
(much) by creating dummy instances. There may be another way with Windows
API to do something a bit smarter but I'm afraid I have no idea what it
might be.

--
Enjoy,
Tony

> [Posted to microsoft.public.word.programming and
> microsoft.public.word.oleinterop. If there is a better place to post
[quoted text clipped - 20 lines]
> Thanks in advance,
> Jeroen
Jeroen ter Hofstede - 25 Oct 2005 08:47 GMT
Tony Jollans schreef:

> Not really much help but nobody else has chimed in so ...
>
> Somebody will probably correct me but if you give control to the user
> (which, of course you must if they are to edit the document) I don't think
> there is any easy way you can stop other applications (or the user) from not
> just using the instance but also, possibly, closing it.

There is actually no problem in giving control to the user. I can track
what is happening there where the user is doing things by way of events
from our global template.
One of our work-arounds (starting a "decoy" Word instance first, which
the browser plug-in would hijack instead of our "real" Word instance)
fails because the user can open this by double-clicking a Word
document, and then close. So, that is not the core problem, it is only
a failure of the workaround.

> You can keep a reference to your document so that you don't need to worry
> which document is active - which may solve your immediate problem - but for
[quoted text clipped - 4 lines]
> solve _your_ problem, it could, of course, cause problems for other
> applications which try to use the Word instance.

We are using this approach, and it works fine when the user works
normally with it. Unfortunately, when another application (again, the
main culprit is opening a Word document in the browser) tries to use
Word, it may use the instance that we started. And it appears to happen
then that Word is thoroughly confused on what is happening and who is
in control. Calling functions in the template fails. Trying to activate
our own document before that fails. Currently our only working
workaround is informing the user to either close the browser, or bring
our applications document to the foreground manually... After which
things resume to work like they should.

> Normally the instance returned via GetObject is indeterminable in advance if
> there are multiple instances of an application running so you don't gain
> (much) by creating dummy instances.

It seems to be the first one started that is selected by GetObject, I
even believe that this is documented.

> There may be another way with Windows
> API to do something a bit smarter

Yes, I was hoping for something like that.

> but I'm afraid I have no idea what it
> might be.

Pity. Still, thanks a lot for your interest and effort!

Regards,
Jeroen
Howard Kaikow - 26 Oct 2005 05:49 GMT
I vaguely recall a discussion a number of years ago that indicated that the
safest way to proceed would be to first create a NEW instance of Word as a
decoy, the create another NEW instance that you actually use.
Jeroen ter Hofstede - 26 Oct 2005 07:51 GMT
Howard Kaikow schreef:

> I vaguely recall a discussion a number of years ago that indicated that the
> safest way to proceed would be to first create a NEW instance of Word as a
> decoy, the create another NEW instance that you actually use.

Yes, thats exactly what we've tried. It is not waterproof, however. The
decoy Word instance is not only used by other applications like the
browser plug-in, but it is also used when the user opens a Word
document manually (e.g. by double-clicking a Word document). When the
user closes that one, the decoy Word instance is gone, too.

Thanks anyway,
Jeroen
Howard Kaikow - 26 Oct 2005 16:24 GMT
> Howard Kaikow schreef:
>
[quoted text clipped - 7 lines]
> document manually (e.g. by double-clicking a Word document). When the
> user closes that one, the decoy Word instance is gone, too.

Yes, but you are not using the decoy instance.

If necessary, start more than one decoy instance.
Tony Jollans - 26 Oct 2005 18:12 GMT
No matter how many decoy instances you start you can not guarantee anything.

Think what happens when you are a user. If you want to open a Word Document
you can press Alt+Tab one or more times until you find an instance of Word
and use it to open the document. If you have multiple instances of Word you
don't care which instance you use - the first one you find is good enough.
The order in which you scroll through instances of applications depends on
the order in which you have used them previously and you cannot set any
particular instance as not for such use (this is not technically true as it
is possible programmatically to start hidden applications which don't appear
in  the Alt+Tab list - but you cannot do this from the UI).

When a program (Browser, Explorer, etc.) wants to open a Word document it
scrolls through all the available applications until it finds a Word one and
uses it. Just like the user, it doesn't care which instance it uses - the
first one it finds is good enough. Just as with the user, the order of
application instances checked depends on what has gone before. Programs,
however, may check hidden application instances as well as visible ones
(although if they want a visible one they should only check visible ones)
and, AFAIK, there is no way to set an application 'very hidden' and even if
there were it wouldn't suit because you need your instance of Word to be
visible for the user.

In theory, if you create multiple instances, you might think you are
reducing the odds but, in practice, I don't think that's the case. You also
have the problem of extra resource usage, and of tidying up afterwards. I
don't think there is anything you can do to stop Word instances being
hijacked as you describe. It might be possible, however, to force your
browser to create a new instance rather than trying to find an existing one,
I don't know - if not, I fear you are stuck with the issue. It should not,
however, interfere with your program and if you have object pointers set
they should remain valid. Can you give any specific examples of something
which fails?

--
Enjoy,
Tony

> > Howard Kaikow schreef:
> >
[quoted text clipped - 13 lines]
>
> If necessary, start more than one decoy instance.
Howard Kaikow - 26 Oct 2005 19:16 GMT
Where possible, code should be using hidden instances.
And, tho i've never tried it, there might be a way to prevent a particular
instance from closing by using Application events  on that instance.
Richard Williams - 26 Nov 2005 16:47 GMT
Have you seen...
http://support.microsoft.com/?id=311765
Not sure what your app is/does but this control will host any MS Office app
exclusively.
Hope it helps
Richard

> [Posted to microsoft.public.word.programming and
> microsoft.public.word.oleinterop. If there is a better place to post
[quoted text clipped - 20 lines]
> Thanks in advance,
> Jeroen
Jeroen ter Hofstede - 27 Nov 2005 19:07 GMT
> Have you seen...
> http://support.microsoft.com/?id=311765

No, I hadn't seen that one yet. Judging from the abstract it may be
of help. I'll look into it. Thanks a lot!

> Not sure what your app is/does but this control will host any MS Office app
> exclusively.
[quoted text clipped - 25 lines]
> > Thanks in advance,
> > Jeroen
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.