.NET互操作:找到一个正在运行的COM对象与C#的所有实例 [英] .NET Interop: Find All instances of of a running COM object with C#

查看:366
本文介绍了.NET互操作:找到一个正在运行的COM对象与C#的所有实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过自动化命令行工具,一些Office应用程序(Word和PowerPoint)。

I am automating some Office application (Word and PowerPoint) via command-line tool.

我想我的工具需要做的就是找​​到Word的所有正在运行的实例。

One thing my tool needs to do is locate all the running instances of Word.

我知道如何让一个参考实例之一...

I know how to get a reference to one of the instances...

Object running_obj = null;
{
    running_obj = System.Runtime.InteropServices.Marshal.GetActiveObject(progid);
}
catch (System.Exception)
{
    //failed to find the object;
}
if (running_obj!=null)
{
   var running_obj_type = System.Type.GetTypeFromProgID(progid);
   Microsoft.Office.Interop.Word.Application running_obj_wrapper;
   running_obj_wrapper = 
            (Microsoft.Office.Interop.Word.Application)
            System.Runtime.InteropServices.Marshal.CreateWrapperOfType(
                  running_obj, running_obj_type);
}

我的提问

如何找到的所有的应用程序的情况下,我找的,不只是他们中的一个。

My question

How to find all the instances of the application I am looking for, not just one of them.

请注意:虽然我的具体问题是关于Office应用程序,上午上午的的兴趣答案,都比较一般

NOTE: Although my specifics question is about Office applications, am am also interested in answers that are more general.

推荐答案

还没有尝试过。但它看起来像正确的解决方案。从奥利弗·博克博客

Have not tried it. But it looks like the right solution. From Oliver Bock blog.

这篇关于.NET互操作:找到一个正在运行的COM对象与C#的所有实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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