Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Using TerminateProcess()on a 16 Bit application

Posted on 1998-11-08
12
Medium Priority
?
297 Views
Last Modified: 2013-12-03
I have an installation program that is written in win32 that needs to call a bunch of old win16 programs that will actually do the installation.  

I would like to give the user the ability to abort the intallation process as these win16 programs have been known to lock up.  But if I call TerminateProccess() on the 16 bit process handle it does not termiante the proccess.  The TerminateProccess Prcedure returns 0--indicating an error occured and GetLastError() returns 6--indicating that the handle is invalid.

However the handle is not invalid.  If I replace the 16 bit program EXEs with 32 bit "dummy" EXEs, then I can kill the 32 bit process fine (with the identical code--no need to even recompile.)  

Why can't I kill the 19 bit processes and is there a way to do so?

This was tested under NT only.  It needs to work in NT, 98, and 95.
0
Comment
Question by:nietod
  • 5
  • 5
  • 2
12 Comments
 
LVL 20

Expert Comment

by:Madshi
ID: 1415850
I'm using TerminateProcess to terminate 16bit application. But I'm doing it with win95/98. And, I'm using toolhelp functions to find a process called "winoa386".
So please try your solution on win95. If it doesn't work there - you'll have the wrong handle. Don't know why. Then please use toolhelp functions (or for NT use "psapi.dll")...

Regards, Madshi.
0
 
LVL 86

Expert Comment

by:jkr
ID: 1415851
On NT, the best choice would be to terminate NTVDM.EXE - but as this also would kill all other 16bit apps, it is useless...
But what about spawning a 16bit 'terminator' that uses the good (?) ol' 16bit 'EnumTaskWindows()', 'IsTask()' and 'TerminateApp()' Win16 APIs (all you have to make sure is specifying 'CREATE_SHARED_VDM' whan calling 'CreateProcess()')? Just an idea...
0
 
LVL 22

Author Comment

by:nietod
ID: 1415852
Well this is for legacy stuff, so I'm not going to put too much work into it.  (And I don't even know if I could create a 16 bit app anymore.)  Do you know for sure that simple means like TerminateProcess() won't work?  (If so, answer and I'll call it quits, I'm not loosing sleep over this.)
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 20

Expert Comment

by:Madshi
ID: 1415853
With Win95/98, TerminateProcess works (at least, if you have the right handle).
I don't know how it is with NT. I've something in mind that you can enumerate the dos processes with "psapi.dll", too. But I'm not so sure about it. However, I think, there are 32bit apis for this purpose in NT.
0
 
LVL 86

Expert Comment

by:jkr
ID: 1415854
nietod, at least for NT there's a suitable solution for you (see, i'm a curious guy ;-)

/*
 *  compile: cl kill16.cpp /link kernel32.lib
 */

#include <windows.h>
#include <stdio.h>

long    main    (   int     argc,
                    char**  argv
                )
{
    BOOL                bRes;

    STARTUPINFO         si;
    PROCESS_INFORMATION pi;
    HANDLE              hProcess;

    ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

    si.cb   =   sizeof  (   STARTUPINFO);

    bRes    =   CreateProcess   (   NULL,
                                    "h:\\programs\\mahjongg\\mjwin.exe",
                                    NULL,
                                    NULL,
                                    FALSE,
                                    NORMAL_PRIORITY_CLASS | CREATE_SEPARATE_WOW_VDM,
                                    NULL,
                                    "h:\\programs\\mahjongg",
                                    &si,
                                    &pi
                                );

    if  (   bRes)
        {
            printf  (   "PH:0x%.8x TH:0x%.8x PID:%d TID:%d\n",
                        pi.hProcess,
                        pi.hThread,
                        pi.dwProcessId,
                        pi.dwThreadId
                    );

            Sleep   (   5000);

            if  (   !TerminateProcess   (   pi.hProcess,    0))
                {
                    printf  (   "Error:%d\n",   GetLastError    ());
                }
        }
     else   printf  (   "\n\tERROR creating process: %d\n\n",  
                        GetLastError    ()
                    );

    return  (   0);
}

NOTE that 'CREATE_SEPARATE_WOW_VDM' apparenty did the trick...

(well, found no other 16bit app than 'mahjongg' <lol>)
0
 
LVL 22

Author Comment

by:nietod
ID: 1415855
Great.  I will try that in an hour or two.  If it works (it should) I'll let know know...
0
 
LVL 86

Expert Comment

by:jkr
ID: 1415856
And - does it work (well, it should...) ?
0
 
LVL 22

Author Comment

by:nietod
ID: 1415857
By an hour or two, I meant a programmer's hour or two.  I'll let you know by march...
0
 
LVL 86

Expert Comment

by:jkr
ID: 1415858
;-)
Fine - take you time, i'll leave for home now anyway ( it's almost 10pm here, which is late even for me <s>)
0
 
LVL 22

Author Comment

by:nietod
ID: 1415859
jkr, that did the trick!.  And look it only took me 5 (programmer) minutes to test it.

answer away
0
 
LVL 86

Accepted Solution

by:
jkr earned 280 total points
ID: 1415860
OK - glad it worked ;-)
0
 
LVL 22

Author Comment

by:nietod
ID: 1415861
Adjusted points to 75
0

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question