🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #3974

Re: OpenProcess() returns different handles

#3974
From: Bob Gonder
Date: Mon, 10 Apr 2006 16:37
32 lines
2077 bytes
Wiebe Vos wrote:

>I want to use the returned handle to check if the program is (still) alive
>and be able to kill it.

The hProcess member of the PROCESS_INFORMATION structure you passed to
CreateProcess() should give you that handle.

{Note: I am not recommending this code. It is for illustration
purposes only}

    if( CreateProcess( 0, command, 0, 0, FALSE, NORMAL_PRIORITY_CLASS,
		 0, 0, &si, &pi ) )
    {
	CloseHandle( pi.hThread ); 
	do{
		WaitForSingleObject( pi.hProcess, 100);
		GetExitCodeProcess ( pi.hProcess, &exitCode);
	}while( exitCode == STILL_ACTIVE );

	CloseHandle( pi.hProcess ); 
    };

>However GetExitCodeProcess ( returnedHandle, &exitCode) gives exitCode=0.

Did you check the return value of the function itself?

	if( ! GetExitCodeProcess ( pi.hProcess, &exitCode) )
		ReportError( "GetExitCodeProcess", GetLastError() );

One also wonders why you ask for the handle to be inheritable (true)?
> OpenProcess ( PROCESS_ALL_ACCESS,  true, processInfo.dwProcessId)
Technical Details
Message-ID: <ri0l32h5ugssjue5e4cs11c4tc1nc40thn@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <44397058@newsgroups.borland.com> <443974ee$1@newsgroups.borland.com> <443a1485$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,8a9918c2e9877ca0
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: OpenProcess() returns different handles
Date: Mon, 10 Apr 2006 09:37:02 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <ri0l32h5ugssjue5e4cs11c4tc1nc40thn@4ax.com>
References: <44397058@newsgroups.borland.com> <443974ee$1@newsgroups.borland.com> <443a1485$1@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 69.69.89.106
X-Trace: newsgroups.borland.com 1144687022 69.69.89.106 (10 Apr 2006 09:37:02 -0700)
Lines: 35
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail