How to reference apps opened by called script?

Batch, ASP, JScript, Kixtart, etc.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
kenthompson
Posts: 14
Joined: Fri Nov 13, 2009 12:41 am

How to reference apps opened by called script?

Post by kenthompson » Wed Feb 10, 2010 10:37 pm

Hello,
I have an hta that calls a vbs, which in turn instantiates MS Word and MS Excel. It scrapes the word doc (which must follow a certain format) and with info gleaned from the user in the hta creates a spreadsheet out of the data from the word doc. (on which the user will choose row specific options from dropdowns and then load into Quality Center as requirements). While this process is happening the hta GUI is running a "processing..." window waiting for the process to finish. The "processing..." window has a cancel button to kill it all if something is wrong.
So, the problem I am trying to address is that when the doc is not properly formatted it can obviously cause problems for the scraping of the word doc. In certain situations this can cause a loop that is too tight for my original 'cancel' routine to catch it, and the app is hung. The original cancel routine was simply enviroment variables as flags that got checked during processing.
So, I reworked it and now my cancel routine is a WMI process that kills the wscript.exe (this all happens in the hta, off the cancel button click event).
What I cannot figure out is how to properly shut down Word and Excel when canceling. They both get created in the vbs with regular Set objWord = CreateObject ("Word.application") syntax.
Is there a way to pass the objWord back to the hta so it can close and quit the applications? Or, less attractive but certainly workable, is there a way to capture the ProcessIDs of these apps? I know I can kill all running excel.exe and winword.exe, but I'd rather not kill other docs the user might have open and possibly cause a loss of data. I tried to find some WMI unique property to ID them, but the only thing I could see was ParentProcessID, which would have worked except the parent of the apps is not the wscript.exe process, but a svchost process. So that doesn"t help.
Any suggestions will be appreciated.

Thanks,
Ken

User avatar
kenthompson
Posts: 14
Joined: Fri Nov 13, 2009 12:41 am

How to reference apps opened by called script?

Post by kenthompson » Wed Feb 10, 2010 10:37 pm

Hello,
I have an hta that calls a vbs, which in turn instantiates MS Word and MS Excel. It scrapes the word doc (which must follow a certain format) and with info gleaned from the user in the hta creates a spreadsheet out of the data from the word doc. (on which the user will choose row specific options from dropdowns and then load into Quality Center as requirements). While this process is happening the hta GUI is running a "processing..." window waiting for the process to finish. The "processing..." window has a cancel button to kill it all if something is wrong.
So, the problem I am trying to address is that when the doc is not properly formatted it can obviously cause problems for the scraping of the word doc. In certain situations this can cause a loop that is too tight for my original 'cancel' routine to catch it, and the app is hung. The original cancel routine was simply enviroment variables as flags that got checked during processing.
So, I reworked it and now my cancel routine is a WMI process that kills the wscript.exe (this all happens in the hta, off the cancel button click event).
What I cannot figure out is how to properly shut down Word and Excel when canceling. They both get created in the vbs with regular Set objWord = CreateObject ("Word.application") syntax.
Is there a way to pass the objWord back to the hta so it can close and quit the applications? Or, less attractive but certainly workable, is there a way to capture the ProcessIDs of these apps? I know I can kill all running excel.exe and winword.exe, but I'd rather not kill other docs the user might have open and possibly cause a loss of data. I tried to find some WMI unique property to ID them, but the only thing I could see was ParentProcessID, which would have worked except the parent of the apps is not the wscript.exe process, but a svchost process. So that doesn"t help.
Any suggestions will be appreciated.

Thanks,
Ken

Locked