Solved

I want to Terminate NT process unconditionally

Posted on 2002-07-04
6
151 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

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…
Cloud-based technologies and services will continue to grow in popularity in 2017 thanks to the simple, scalable and cost-effective solutions they deliver. Here are three areas where cloud adoption is poised to really take off.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

910 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