Click here to Skip to main content
15,895,084 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Comparing Real Numbers Pin
David Crow26-Jul-04 6:43
David Crow26-Jul-04 6:43 
GeneralDisplaying build times Pin
Chris Hills26-Jul-04 4:25
Chris Hills26-Jul-04 4:25 
GeneralRe: Displaying build times Pin
Tomasz Sowinski26-Jul-04 4:38
Tomasz Sowinski26-Jul-04 4:38 
GeneralRe: Displaying build times Pin
Chris Hills1-Aug-04 2:10
Chris Hills1-Aug-04 2:10 
GeneralDocument template problem Pin
dolph_loe26-Jul-04 3:19
dolph_loe26-Jul-04 3:19 
GeneralRe: Document template problem Pin
Tomasz Sowinski26-Jul-04 4:51
Tomasz Sowinski26-Jul-04 4:51 
GeneralRe: Document template problem Pin
dolph_loe28-Jul-04 10:51
dolph_loe28-Jul-04 10:51 
GeneralTerminating Process Pin
GTS202026-Jul-04 2:28
GTS202026-Jul-04 2:28 
Hi All,

I am spawning a process from a service. The spawned process hungs for various reasons, (corrupted data, deadlock). I am expecting the process has to complete the task with in the expected time limit, if it exceeds the limit I want to terminate the process (no mercy or graceful, just terminate the process).

The spawnng of the process, counting the time and termination of process all done in C++. Some time I am not able to terminate the process, the error message was "Access denied". I dont want this also happens. The program has to terminate the process even, the process in any state. How to do that? What security permissions I have to give?

Here is the code snippet of the teminate application,
=========================================================
static DWORD WINAPI TerminateApp( DWORD dwPID, DWORD dwTimeout )
{
HANDLE hProc ;
DWORD dwRet ;

// If we can't open the process with PROCESS_TERMINATE rights,
// then we give up immediately.
hProc = OpenProcess(SYNCHRONIZE|PROCESS_TERMINATE, FALSE,
dwPID);

if(hProc == NULL)
{
return TA_FAILED ;
}

// TerminateAppEnum() posts WM_CLOSE to all windows whose PID
// matches your process's.
EnumWindows((WNDENUMPROC)TerminateAppEnum, (LPARAM) dwPID) ;

// Wait on the handle. If it signals, great. If it times out,
// then you kill it.
if(WaitForSingleObject(hProc, dwTimeout)!=WAIT_OBJECT_0)
dwRet=(TerminateProcess(hProc,0)?TA_SUCCESS_KILL:TA_FAILED);
else
dwRet = TA_SUCCESS_CLEAN ;

CloseHandle(hProc) ;

return dwRet ;
}


static BOOL CALLBACK TerminateAppEnum( HWND hwnd, LPARAM lParam )
{
DWORD dwID ;

GetWindowThreadProcessId(hwnd, &dwID) ;

if(dwID == (DWORD)lParam)
{
PostMessage(hwnd, WM_CLOSE, 0, 0) ;
}

return TRUE ;
}

=========================================================

All suggestion appreciated.

Thanks



GTS

GeneralRe: Terminating Process Pin
David Crow26-Jul-04 3:46
David Crow26-Jul-04 3:46 
GeneralRe: Terminating Process Pin
GTS202026-Jul-04 5:20
GTS202026-Jul-04 5:20 
GeneralRe: Terminating Process Pin
David Crow26-Jul-04 8:30
David Crow26-Jul-04 8:30 
GeneralGetting the HACCEL handle... Pin
0v3rloader26-Jul-04 2:03
0v3rloader26-Jul-04 2:03 
GeneralRe: Getting the HACCEL handle... Pin
Antony M Kancidrowski26-Jul-04 2:19
Antony M Kancidrowski26-Jul-04 2:19 
GeneralCString Problems Pin
#realJSOP26-Jul-04 0:54
mve#realJSOP26-Jul-04 0:54 
GeneralRe: CString Problems Pin
palbano26-Jul-04 7:33
palbano26-Jul-04 7:33 
Questionno copy constructor? Pin
feline_dracoform26-Jul-04 0:09
feline_dracoform26-Jul-04 0:09 
AnswerRe: no copy constructor? Pin
David Crow26-Jul-04 3:53
David Crow26-Jul-04 3:53 
GeneralRe: no copy constructor? Pin
feline_dracoform27-Jul-04 2:02
feline_dracoform27-Jul-04 2:02 
GeneralRe: no copy constructor? Pin
David Crow27-Jul-04 3:39
David Crow27-Jul-04 3:39 
AnswerRe: no copy constructor? Pin
palbano26-Jul-04 7:53
palbano26-Jul-04 7:53 
GeneralRe: no copy constructor? Pin
feline_dracoform27-Jul-04 1:12
feline_dracoform27-Jul-04 1:12 
Generaldisable a submenu item on runtime in an MFC app Pin
caykahve25-Jul-04 23:35
caykahve25-Jul-04 23:35 
GeneralRe: disable a submenu item on runtime in an MFC app Pin
Anonymous25-Jul-04 23:45
Anonymous25-Jul-04 23:45 
GeneralRe: disable a submenu item on runtime in an MFC app Pin
caykahve25-Jul-04 23:52
caykahve25-Jul-04 23:52 
GeneralRe: disable a submenu item on runtime in an MFC app Pin
V.25-Jul-04 23:47
professionalV.25-Jul-04 23:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.