4

Background

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

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.

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

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

This won't find Applications that don't have Documents open. I've tried the same thing for Word -- I have 5 Word apps open -- no documents in any of them (and 5 "WINWORD.EXE"s running under task manager) -- call this, and look for objects that cast to Application -- you find 5 of them -- but all 5 are the same object. -- If each has a document open, then you can enumerate those and find their .Applications; otherwise, you're SOL.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.