Getting PID of new Word.ApplicationClass()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • inxanu
    New Member
    • Feb 2007
    • 9

    Getting PID of new Word.ApplicationClass()

    First of all, I am unsure as to where to post it, so please let me know (or move it) to where it should be.

    I create an instance of word as follows
    Code:
    Word.ApplicationClass wd = new Word.ApplicationClass();
    wd.Caption = "My Word";
    int wordHandle =  FindWindow("Opusapp", wd.Caption);
    Questions:
    1)
    Word.Applicatio nClass wd = new Word.Applicatio nClass();
    creates the winword.exe process,right?t hen...how can I get the Process Id of that word instance I have just created?thus I can kill it at a later stage by
    Code:
                    Process[] wordProcesses = Process.GetProcessesByName("WINWORD");
                    foreach (Process p in wordProcesses)
                    {
                        if (p.Id = myProcessId)
                            p.Kill;
    }
    2) When I open word using my app, the caption appears as "My Word", however sometimes (haven't been able to reproduce it always) when I open word using the shortcut to microsoft word 2007, the word document also has the "My Word" caption...Other times, it shows the expected caption "Document1" , etc...Why is this happening?Where could I get in-depth information about Word.Applicatio nClass?

    If anyone can bring some light to these issues...

    Many thanks
  • aryanbs
    New Member
    • Mar 2009
    • 42

    #2
    Why you want to kill it, you can Quit it normally
    You can make sure its been closed after quit running following code:

    Code:
     try
                {
                    //release same way like below if you have any other object from word
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(WordApp);
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
    
                catch (Exception ex)
                {
                    WordApp = null;
                }
    More Info here


    Comment

    Working...