Service cannot send console event.

112 views
Skip to first unread message

mmid...@d2.com

unread,
May 8, 1997, 3:00:00 AM5/8/97
to

Hello,
I am writing an NT 4.0 service that creates a child process
which in turn creates several of its own children.
I am using the CREATE_NEW_PROCESS_GROUP flag
in the first call to CreateProcess.
In theory, this will allow my service to later call
GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT,..)
to kill the child process and all of its descendants.

However, I am getting ERROR_INVALID_HANDLE returned
from GenerateConsoleCtrlEvent when I attempt to do this.
Any idea why?

When I run the program normally (not as a service) this
strategy works as expected.

I have tried toggling the "allow service to interact with
desktop" flag as well as having the service log in as
my user account and still get the same error.

Any help is appreciated.
Thanks.

-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet

Felix Kasza [MVP]

unread,
May 9, 1997, 3:00:00 AM5/9/97
to

mmiddler,

> However, I am getting ERROR_INVALID_HANDLE returned
> from GenerateConsoleCtrlEvent when I attempt to do this.
> Any idea why?

No, sorry. I can only suggest an alternate strategy: Either use a
named event, or pass the handle to an inheritable one. The children
would basically poll the event or wait on it in a separate thread.
When it's time to die, your main process sets the event, and so on.

Cheers,
Felix.

----------
If you post a reply, kindly refrain from emailing it, too.

mmid...@d2.com

unread,
May 12, 1997, 3:00:00 AM5/12/97
to

In article <337308ff...@msnews.microsoft.com>,

fel...@mvps.org (Felix Kasza [MVP]) wrote:
>
> mmiddler,
>
> > However, I am getting ERROR_INVALID_HANDLE returned
> > from GenerateConsoleCtrlEvent when I attempt to do this.
> > Any idea why?
>
> No, sorry. I can only suggest an alternate strategy: Either use a
> named event, or pass the handle to an inheritable one. The children
> would basically poll the event or wait on it in a separate thread.
> When it's time to die, your main process sets the event, and so on.
>

You are assuming that I have access to the source code for the child
processes, which I do not. So your proposed solution will not work for
me. I'm open to other suggestions.

Steven Doerfler

unread,
May 12, 1997, 3:00:00 AM5/12/97
to

mmid...@d2.com wrote:

>In theory, this will allow my service to later call
>GenerateConsoleCtrlEvent(CTRL_BREAK_EVENT,..)
>to kill the child process and all of its descendants.

GenerateConsoleCtrlEvent() fails whenever the calling process and the
specified process group don't share the same console. Perhaps your
service has no associated console, or perhaps you're specifying
CREATE_NEW_CONSOLE in the call to CreateProcess. Try using
FreeConsole and AllocConsole in your service before starting the new
process and see if that makes a difference.

Hope this helps,

Steven Doerfler
Lugaru Software, Ltd.


Reply all
Reply to author
Forward
0 new messages