I have code which starts Word application instance as follows
Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application();
app.Caption = "abcd_" + DateTime.Now.Ticks.ToString();
I now need to know process id of the word instance that was started. I cannot use FindWindow to get window handle and GetWindowThreadProcessId to get process id from handle as the code does not work on Windows server 2008.
I get all word processes by using Process.GetProcessesByName("WINWORD"). Is there any property of Process which can give me value that we set in app.Caption ? If not, is there any other property of Word.Application which I can set and later on read from Process array to identify correct instance of Word ?
What about that (untestet):
Updated
The
wdApp
should be the started word. And you get the process id throughwordProcess
instance.