Thread: Microsoft Word Automation

  1. #1
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058

    Microsoft Word Automation

    First a little backgound info. We have a networked application in which our midrange, (AS400) will create a MS Word template and forward the template to a remote computer. The remote computer will "fire up" MS Word when it receives the template and have Word add some finishing touches. Word will print the document and then save the document using Save As with a timestamp to name the document. The remote computer is an unattended workstation meaning that an administrator initially logs into the computer and then locks the computer.

    The problem that we have is that Word occasionally hangs when the Word Automation starts the Save As function. what I need to do is somehow monitor Word on the remote computer to determine if it has hung while it is attempting to do Save As.

    Any suggestions?

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,273
    Does it create the final document file before it hangs or after? If it's after you can watch the file system, check for when the file exists and restart the process if it hasn't been seen for say 30 seconds.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    When Word hangs at "Save As" there is absolutely nothing in the destination folder related to the document that Word is trying to save. So, monitoring the destination folder isn't an option.

    I was thinking about possibly monitoring the title area in the MS Word window. When the document title changes on a regular basis, I know everything is working fine. If the same doc name in the title area for an extended period of time, I can then assume there is a problem. IMHO, this is an ugly solution. But I just don't know of any other options.

    Thanx for the input.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    How are you automating Word?

    You can attach your app to the running instance of Word and get Word to report events, using COM / OLE etc.



    http://support.microsoft.com/kb/309294/

    http://support.microsoft.com/kb/183599/EN-US/

    http://support.microsoft.com/kb/181473/
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    How are you automating Word?
    Unfortunately, the client/server with Word automation is a proprietary 3rd party app. So, we have no control over the Word automation of the application. This application is running 24/7 which means that anywhere from a 100 to over 500 documents a day are processed by Word. Thus, we believe that Word just calls it quits after processing a few thousand documents. After all, it's really bloatware and IMHO is not really capable of handling this type of production environment.

    The links are a great help. Unfortunately, I have no MFC experience and my Office automation experience is limited to the trivial opening up of a Excel spreadsheet to display calculation results. So, I'll write this util using C# since there's more automation example code and documentation for C#. It also appears the best way for me to get this util up and running ASAP.

    Thanx again for the info. It kept me from going off on a really bad tangent.

  6. #6
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by BobS0327 View Post
    When Word hangs at "Save As" there is absolutely nothing in the destination folder related to the document that Word is trying to save. So, monitoring the destination folder isn't an option.
    Huh? Sounds like exactly what you need. If no file appears within 30 seconds, then something failed. Try again.

    I was thinking about possibly monitoring the title area in the MS Word window. When the document title changes on a regular basis, I know everything is working fine. If the same doc name in the title area for an extended period of time, I can then assume there is a problem. IMHO, this is an ugly solution. But I just don't know of any other options.
    BARF.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So word on the remote machine is running 24/7 as well, just hanging around waiting for the next remote connection to arrive?

    For XP
    Control Panel -> Admin Tools -> Performance
    You can use this to monitor the state of word (say the amount of memory allocated) and track this over time. You end up with lots of pretty graphs like this (see attached).
    perfmon can save all this to a file, so it might make for an interesting bug report to Microsoft if you find something interesting and repeatable

    If it does prove to be a resource leak, you could arrange for word to be killed off and restarted at periodic intervals.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  8. #8
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Watch for GDI leaks also.

    I found one in a commercial PDF creator while coding online share trading software.

    You will not see the memory used rise if a GDI leak and I would expect a print to fail as the PC can no longer create fonts etc.

    You can add GDI Objects to the task manger display and see if it is releasing them all successfully.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  9. #9
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    Watch for GDI leaks also.
    GDI leaks may just be the problem. I've been watching the app over the last 48 hours and the GDI objects count increases very slowly. But it's increasing.

    Thanx Novacain, Salem for the help

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Slow, as in "one object per file processed" kind of slow?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  11. #11
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    It's more like a yo yo incremental effect. GDI objects will increase by 6, a few milliseconds later GDI objects will decrease by 4 with a net increment of 2. A few milliseconds after that GDI objects will increase by 8 and later decrease by 9 with a net decrement effect of 1. Monitoring GDI objects for about an hour of this yo-yoing will produce an approximate net increase of 5 to 25 GDI objects on average.

    If there was a way to graph these GDI objects over a long time period, the graph would indicate a slow upward swing.

    In other words, short monitoring time periods produce nothing more than a yo-yo effect. Long monitoring time periods indicate an upward trend on the GDI objects.

  12. #12
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    You can set the perfmon to record over whatever time period you like.
    I used to let it run overnight for example.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  13. #13
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    Quote Originally Posted by BobS0327 View Post
    It's more like a yo yo incremental effect. GDI objects will increase by 6, a few milliseconds later GDI objects will decrease by 4 with a net increment of 2. A few milliseconds after that GDI objects will increase by 8 and later decrease by 9 with a net decrement effect of 1. Monitoring GDI objects for about an hour of this yo-yoing will produce an approximate net increase of 5 to 25 GDI objects on average.

    If there was a way to graph these GDI objects over a long time period, the graph would indicate a slow upward swing.

    In other words, short monitoring time periods produce nothing more than a yo-yo effect. Long monitoring time periods indicate an upward trend on the GDI objects.
    The 'yo yo' effect is usual but the total GDI should remain / return to a constant.

    Can you (over a reasonable time period) track the number of docs produced versus the net increase in GDI?

    Then try the same sort of test with just Word.

    ie Is it Word or the Automation app that is failing to release the GDI.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. brace-enclosed error
    By jdc18 in forum C++ Programming
    Replies: 53
    Last Post: 05-03-2007, 05:49 PM
  3. Dirty Word (Microsoft Word that is, you sicko!)
    By nickname_changed in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 07-02-2005, 07:27 AM
  4. Wrong Output
    By egomaster69 in forum C Programming
    Replies: 7
    Last Post: 01-28-2005, 06:44 PM
  5. Apps that act "differently" in XP SP2
    By Stan100 in forum Tech Board
    Replies: 6
    Last Post: 08-16-2004, 10:38 PM