创建独占字实例 [英] Create exclusive word instance

查看:137
本文介绍了创建独占字实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用c#.net4 winforms应用程序创建一个具有互操作性的单词(14)实例来处理文档。如果某些word文档在我的应用程序之外打开,那么将使用相同的单词实例来扰乱我的应用程序。



简单问题:有什么办法



Btw:找到一些与我的应用程序相关的字词实例

解决方案

有一种解决方案,但它不是一个解决方案漂亮。
主要的问题是Word在ROT(运行对象表)中注册自身,然后其他应用程序可以轻松访问在ROT中注册的Word实例(这是VB GetObject函数实现的)。



所以,在你的应用程序中,你基本上必须做两件事情:


  1. 尝试 GetObject (即查询正在运行的实例的ROT)

  2. 如果你有一个,你知道你有创建一个新的Word实例使用( CreateObject 在VB中,其他语言的过程是不同的)。

  3. 如果你没有得到一个,创建2个新的Word实例。第一个会自动注册在ROT中,第二个不会。

即使终止第一个实例,它也不会追溯注册它本身在ROT中,而其他应用程序一般不会对其引用它来使用,他们会自动创建一个新的实例,这是因为没有其他实例在ROT中注册了,然后会被注册。



也就是说,对于其他应用程序仍然可以获取您的Word实例,所以这种技术不是防弹的。怎么样?因为字ALSO在ROT中注册每个加载的文档。但这是一个很少使用的功能。


i am creating a word (14) instance with interop out of a c# .net4 winforms application to work with a document. If some word document gets opened beyond my application the same word instance will be used an disturbs my application.

Simple question: Is there any way to set my word instance exclusive for my application?

Thanks in advance.

Btw: Found some stuff with exclusive/word/office/isolated/block/instance but no answers anyhow.

解决方案

There's sort of a solution, but it's not pretty. The main issue is that Word registers itself in the ROT (Running Object Table), and other applications can then easily get access to the instance of Word registered in the ROT (that's what the VB GetObject function does for instance).

So, in your app, you'd basically have to do 2 things

  1. Try to GetObject (ie query the ROT for a running instance)
  2. If you get one, you know you HAVE to create a new instance of Word to use (CreateObject in VB, the process is different in other langs).
  3. If you DON'T get one, you have to create 2 new instances of Word. The first will automatically register itself in the ROT, the second won't. Use the second instance, and quite the first instance.

Even though you terminate that first instance, It won't "retroactively" register itself in the ROT, and other applications will generally not object a reference to it to use, they'll automatically create a new instance, which, since no other instance is registered in the ROT anymore, will then get registered.

That said, it is still possible for other apps to get at your instance of Word, so this technique isn't bulletproof. How? Because Word ALSO registers each loaded DOCUMENT in the ROT. But that's a pretty seldom used feature.

这篇关于创建独占字实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆