背景
我正在通过命令行工具自动化一些 Office 应用程序(Word 和 PowerPoint)。
我的工具需要做的一件事是找到所有正在运行的 Word 实例。
我知道如何获得对其中一个实例的引用......
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);
}
我的问题
如何找到我正在寻找的应用程序的所有实例,而不仅仅是其中一个。
注意:虽然我的具体问题是关于 Office 应用程序的,但我也对更一般的答案感兴趣。