Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Using TerminateProcess()on a 16 Bit application

Posted on 1998-11-08
12
Medium Priority
?
300 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 
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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
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…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

580 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