2

I have an app that opens MSWord via Interop

            wrdApp = new Word.Application();
            wrdApp.Visible = false;

So that while debugging, if I jsut kill the session, I'm left with a bunch of instances of WINWORD.EXE*32 running.

Is there a way to make these instances visible... Keeping in mind that the program that created these instances is closed.

And yes the running program does clean up any instances it opens.

enter image description here

kevcoder
  • 883
  • 1
  • 15
  • 29
  • Easiest solution IMO would be, while you're debugging, just to set `wrdApp.Visible = true;`. Once you're done debugging, just set it back to false. – David Zemens May 23 '13 at 15:56

2 Answers2

0

Try this:

Word.Application App = (Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");

If it does not work, use this:

System.Type objAppType = System.Type.GetTypeFromProgID("Word.Application");

object objApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");

objAppType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, objApp, null);
Daniel Möller
  • 84,878
  • 18
  • 192
  • 214
  • App comes back as an object but I can't set the visible property or add a document. contrary to the documentation, its not finding running instances but creating a new instance. – kevcoder May 23 '13 at 18:22
0

I noteiced that if you have a hidden Word instance opened by interop and user manually opens Msword using the normal msword start icon it opens and unhides the instance being used by interop. (And should NOT be made visible to the user!!)

With this bug You can use it to open your hidden/abandoned instances.

In interop you can have multiple instances of msword.exe, but it feels like MS is helping a bit too much and exposes hidden instances.

Probably my misstake as usual and MS has some smart idea how to work with hidden apps or maybe you are wrong having hidden instaces. Beyond the idea and intention of MSWord.

tofo
  • 388
  • 3
  • 8
  • I can't say that I've ever seen this. Most of our users have Office 2007, we (IT dept) have Office 2013 and I'm using the 2007 interop assemblies. Those hidden instance stay hidden. My actual solution, and I know this will land me on the daily wtf, was to check if in debug mode and set the hidden flag to false. – kevcoder Oct 04 '14 at 15:07