Solved

I want to Terminate NT process unconditionally

Posted on 2002-07-04
6
149 Views
Last Modified: 2010-04-13
Hi Guys

Does anyone know if there is a DLL version of KILL.EXE. I want to be able to kill a process unconditionally.

Reason: I'm creating software that consists of a number of COM/DCOM objects and if one falls over, I want to ensure the rest of them will close and vanish out of the process list.

TerminateProcess doesn't kill them, either that or I'm doing something wrong. I've got the ProcessIDs of the processes and calling TerminateProcess, but they are still in the task list.

It has to be a DLL call. I can incorporate KILL into the app, but that throws up loads of Command windows (not a pretty sight).

All help gratefully received.

Cheers
0
Comment
Question by:OldBob
  • 4
  • 2
6 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 7130273
'TerminateProcess()' takes a process handle, not a PID - you have to call 'OpenProcess()' to obtain it, e.g.

HANDLE hProcess = OpenProcess ( PROCESS_TERMINATE, FALSE, PID);

TerminateProcess ( hProcess, 0);

CloseHandle ( hProcess);

BTW, there are also means to call 'kill.exe' without having a command prompt pop up...
0
 
LVL 1

Author Comment

by:OldBob
ID: 7130703
Cheers jkr

I'll give it a crack. Any idea how I would call Kill.exe without the cmd box appearing, (just as a secodary option)

Bob
0
 
LVL 86

Accepted Solution

by:
jkr earned 150 total points
ID: 7130730
ShellExecute ( NULL, "open", "kill.exe", "<PID>", NULL, SW_HIDE);

or

BOOL ExecuteAndWaitForCompletion    (   LPSTR   pszCmd)
{
    STARTUPINFO         si;
    PROCESS_INFORMATION pi;

    BOOL                bRes;

    DWORD               dwCode  =   0;

    ZeroMemory  (   &si,    sizeof  (   STARTUPINFO));

    si.cb           =   sizeof  (   STARTUPINFO);
    si.dwFlags      =   STARTF_USESHOWWINDOW;
    si.wShowWindow  =   SW_HIDE;

    bRes    =   CreateProcess   (   NULL,
                                    pszCmd,
                                    NULL,
                                    NULL,
                                    TRUE,
                                    NORMAL_PRIORITY_CLASS,
                                    NULL,
                                    NULL,
                                    &si,
                                    &pi
                                );

    WaitForSingleObject (   pi.hProcess,    INFINITE);

    GetExitCodeProcess  (   pi.hProcess,    &dwCode);

    CloseHandle (   pi.hProcess);
    CloseHandle (   pi.hThread);

    return  (   bRes);
}

Call it like

ExecuteAndWaitForCompletion ( "kill.exe <pid>");

:o)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 86

Expert Comment

by:jkr
ID: 7130814
Oh, BTW, you might want to ask such questions in one of the programming topic areas to get a better response...
0
 
LVL 1

Author Comment

by:OldBob
ID: 7131167
No need to ask anyone else... :) It works a treat.

Cheers Mate.
0
 
LVL 86

Expert Comment

by:jkr
ID: 7133104
>>No need to ask anyone else...

That was meant for the "future" - you will just get quicker responses in the Programming TAs, I just "found" your Q by chance :o)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
A Short Story about the Best File Recovery Software – Acronis True Image 2017
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now