From: "chris guilmartin" <chris.guilmartin@channel1.com>
Newsgroups: comp.os.ms-windows.programmer.misc
Subject: detecting dos sessio
Date: 29 Sep 92 04:36:53 EST
Reply-To: "chris guilmartin" <chris.guilmartin@channel1.com>
Distribution: comp
Organization: Channel 1 Communications

Chris Hook writes:
CH>Can someone please give me info on how to detect if a certain DOS
CH>session is present under Windows?
CH>
CH>I start a full screen DOS session via a WinExec call and then 
CH>periodically
CH>test to see if it is still running. If not, I start it up. The 
CH>problem is,
CH>any info I get back from WinExec seems to do no good and I end up 
CH>starting
CH>the DOS session over and over again.

I just attacked this the other day. The great book 'Undocumented Windows'
was helpful, but ultimately indicated that the right way to do this is
to use the Toolhelp function NotifyRegister function to determine when
the application exits. This works for DOS apps as well, since they are
simply executed for Windows by WINOLDAP.EXE. As a side benefit, you can
get the application's DOS return code, if that is useful to you.

Schulman/Maxey/Pietrek (Undocumented Windows) refer you to a magazine
article, but I discovered on Compuserve a tech note by Microsft which 
does the same thing and gives code samples. Look on Compuserve for
keyword TERMWAIT if you have access. 

Microsoft's description of the program follows:

Title: INF: Sample Code Spawns Task and Waits for its Termination
Document Number: Q84456           Publ Date:  8-SEP-1992
Product Name: Microsoft Windows Software Development Kit
Product Version:  3.00 3.10
Operating System: WINDOWS

 Summary:
 TERMWAIT is a file in the Software/Data Library that demonstrates how
 an application can launch a child task and then wait for it to
 complete before executing specific code. TERMWAIT uses notification
 messages from the Toolhelp dynamic-link library (DLL) to determine
 that the child task has completed. The techniques demonstrated by the
 TERMWAIT sample work for both Windows and MS-DOS (non-Windows) child
 tasks.
 TERMWAIT can be found in the Software/Data Library by searching on the
 keyword TERMWAIT, the Q number of this article, or S13429. TERMWAIT
 was archived using the PKware file-compression utility.
 More Information:
 The TERMWAIT sample application calls the NotifyRegister function to
 install a notification callback function before it calls the WinExec
 function to launch the child task. If a callback function is
 registered, it is called before any task in the system terminates. The
 notification callback function calls the TaskFindHandle function to
 fill a TASKENTRY data structure with information about the terminating
 task. When the callback determines that the child task has terminated,
 it notifies the TERMWAIT application.
 When it spawns the child task, TERMWAIT sets its bChildIsExecuting
 global variable to TRUE. The notification callback resets this
 variable to FALSE when the child task is complete. Any code that must
 not execute while the child task is running can query the value of the
 bChildIsExecuting flag. During the wait, any menu selections that
 will cause reentrancy problems should be disabled. Doing so keeps the
 user informed about the options that are presently valid. In the
 TERMWAIT sample, the AfterChildHasTerminated function contains code
 that is executed only after the child task has completed.
 If an application tracks a number of child tasks, its NotifyRegister
 callback function should process both the NFY_STARTTASK and
 NFY_EXITTASK notifications. The callback function uses these
 notifications to maintain a list of child task handles. Note that
 while no two tasks will have the same handle, it is possible for task
 handles to be reused. Consequently, if one task ends and a new task
 begins, the new task can use the same task handle.
 Version 3.1 of the Windows Software Development Kit is required to
 build the TERMWAIT sample. However, the compiled code is compatible
 with both Windows 3.0 and 3.1. Note that because the TOOLHELP.DLL is
 not part of the default installation for Windows 3.0, it must be
 installed into the Windows system directory (by default,
 C:\WINDOWS\SYSTEM) before TERMWAIT will run. The TOOLHELP.DLL file is
 provided as a redistributable file with the Windows 3.1 SDK.
 Additional reference words: 3.00 3.10 softlib TERMWAIT.ZIP synchronize

COPYRIGHT Microsoft Corporation, 1992. ==CIS=MICROSOFT=EOF==


---
 * WinQwk 2.0b#218 * Just a guy made of dots and lines.
--
Channel 1 (R)   Cambridge, MA

Newsgroups: comp.os.ms-windows.programmer.misc