PC Review


Reply
Thread Tools Rate Thread

Processes in Windows 2003

 
 
Darren Kennedy
Guest
Posts: n/a
 
      10th Mar 2004
(Apologies if posting to wrong group. Is there a Windows 2003 Server
dev group?)

When I run the OpenProcess() function on Windows 2003, I continue to
get a non-NULL handle on a process that has terminated.

HANDLE hProcess = OpenProcess(READ_CONTROL, FALSE, <ProcessId>);
while (hProcess)
{
hProcess = OpenProcess(READ_CONTROL, FALSE, <ProcessId>);
// Process terminates but I keep getting a non-NULL hProcess
}

Works as expected on Windows 2000 but not on Windows 2003 Server.

Any ideas?

Thanks
-Darren
 
Reply With Quote
 
 
 
 
John Phillips
Guest
Posts: n/a
 
      10th Mar 2004
OpenProcess will -=not necessarily=- return NULL even if the process has
terminated. The process object will remain valid until all handles to it
are closed (BTW, in your sample code, this will never happen as you keep
creating a new handle to the process on every iteration without ever closing
any).

What are you really trying to accomplish? Are you trying to determine
whether or not the process has exited? In that case, may I suggest either
polling via GetExitCodeProcess() or the more elegant
WaitForSingleObject(hProcess)?


--
John Phillips
MVP - Windows SDK



"Darren Kennedy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> (Apologies if posting to wrong group. Is there a Windows 2003 Server
> dev group?)
>
> When I run the OpenProcess() function on Windows 2003, I continue to
> get a non-NULL handle on a process that has terminated.
>
> HANDLE hProcess = OpenProcess(READ_CONTROL, FALSE, <ProcessId>);
> while (hProcess)
> {
> hProcess = OpenProcess(READ_CONTROL, FALSE, <ProcessId>);
> // Process terminates but I keep getting a non-NULL hProcess
> }
>
> Works as expected on Windows 2000 but not on Windows 2003 Server.
>
> Any ideas?
>
> Thanks
> -Darren



 
Reply With Quote
 
Darren Kennedy
Guest
Posts: n/a
 
      10th Mar 2004
I have a test manager that needs to know when the test (exe's) have
completed.

Both your suggestions work, thank you for those.

My sample code was too abbreviated (see eom). I do call CloseHandle(). Which
is why it worked on Win2k.

Now that I have a solution, I am curious as to why 2003 Server seems to
behave differently.

Thanks again

-Darren



HANDLE hProcess = OpenProcess(READ_CONTROL, FALSE, <ProcessId>);

while (hProcess) {

CloseHandle(hProcess)

hProcess = OpenProcess(READ_CONTROL, FALSE, <ProcessId>);

// Process terminates but I keep getting a non-NULL hProcess on Windows
2003 Server

}

"John Phillips" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...

> OpenProcess will -=not necessarily=- return NULL even if the process has
> terminated. The process object will remain valid until all handles to it
> are closed (BTW, in your sample code, this will never happen as you keep
> creating a new handle to the process on every iteration without ever

closing
> any).
>
> What are you really trying to accomplish? Are you trying to determine
> whether or not the process has exited? In that case, may I suggest either
> polling via GetExitCodeProcess() or the more elegant
> WaitForSingleObject(hProcess)?
>
>
> --
> John Phillips
> MVP - Windows SDK
>
>
>
> "Darren Kennedy" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > (Apologies if posting to wrong group. Is there a Windows 2003 Server
> > dev group?)
> >
> > When I run the OpenProcess() function on Windows 2003, I continue to
> > get a non-NULL handle on a process that has terminated.
> >
> > HANDLE hProcess = OpenProcess(READ_CONTROL, FALSE, <ProcessId>);
> > while (hProcess)
> > {
> > hProcess = OpenProcess(READ_CONTROL, FALSE, <ProcessId>);
> > // Process terminates but I keep getting a non-NULL hProcess
> > }
> >
> > Works as expected on Windows 2000 but not on Windows 2003 Server.
> >
> > Any ideas?
> >
> > Thanks
> > -Darren

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem: Outlook 2003 will not shutdown. Processes still running Rx Microsoft Outlook 3 9th Jan 2009 01:45 PM
Window Titles/Captions of Processes on Windows Server 2003 Tobias Maier Microsoft C# .NET 0 18th Jun 2008 12:08 PM
Debugging two processes question/launching two debug processes =?Utf-8?B?bTExNTMz?= Microsoft C# .NET 4 5th Nov 2004 12:57 AM
Outlook 2003 - Processes won't end Microsoft Outlook 2 3rd Mar 2004 05:40 AM
Watching Your Server Processes article on windows 2003 Paul Richards Microsoft ASP .NET 0 11th Dec 2003 02:04 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:45 AM.