CreateProcess() and WM_ENDSESSION

Under Windows NT4(sp3), how do I CreateProcess() a new process so that the new process will receive a WM_ENDSESSION indicating shutdown?

Simplification:

 A process (the one I'm interested in) has been started by an NT service using CreateProcess().

 When the user selects "log-off", the new process receives a WM_ENDSESSION with TRUE and ENDSESSION_LOGOFF as the parameters. All ok so far.

 Here's the problem:

 When the user selects "shutdown", the new process recieves exactly the same as above. Therefore, I can't tell the difference between a shutdown and a log-out.

 Now for the question:

 Is there something I should do in the parent process before I call CreateProcess()? i.e. How do I make sure that I will receive the WM_ENDSESSION with TRUE and 0 as the parameters (indicating shutdown) in the child?
dogmaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nietodCommented:
I doubt there is anything you can do about this.  I suspect NT allways indicates that the user is logging off, even when they are really shutting down.  
0
nietodCommented:
You are getting the WM_ENDSESSION message right?   the First part of you question sounds like you're not getting the message.  The second part sounds like the LPARAM is never zero.  Is assume that is really your problem.
0
dogmaAuthor Commented:
Yes. I'm not getting the message with WM_ENDSESSION indicating a shutdown (lParam=0) only the one indicating a log off (lParam=ENDSESSION_LOGOFF).
So, how do I make sure I get this message? I've read the help pages a thousand times but to no avail.

If I launch direct from the desktop/CMD, I get the shutdown message correctly. When I use CreateProcess() from a parent process, I don't get the message. The parent process is an NT service, if that makes any difference. In the parameters to CreateProcess(), I pass CREATE_NEW_PROCESS_GROUP and DETACHED_PROCESS.

Obvously I've missed something in the CreateProcess(). So the question is what???!

tia.

0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

dogmaAuthor Commented:
Edited text of question
0
nietodCommented:
Sorry but I am still confussed.  I see two ways of interpretting what you've said.

(1) regardless of whethor or you logout or shut down you get lparam = ENDSESSION_LOGOUT.  That is you always get the message, but lparam is wrong on a shutdown.

(2) You get the message on a logout, but don't get it on a shutdown.

Regardless of your answer.  I probably can't help you, but other experts will probably have the same confussion.
0
dogmaAuthor Commented:
Edited text of question
0
dogmaAuthor Commented:
Edited text of question
0
alexoCommented:
According to the documentation and WINUSER.H, only the ENDSESSION_LOGOFF flag is currently supported (there is no distinction between logoff and shutdown)

Do other processes receive the notification you're waiting for?

0
nietodCommented:
My interpretation of the docs was that it was the only flag supported, but that no flags (i.e. 0) is shutdown and that flag indicates logoff.   I've never tried though.
0
dogmaAuthor Commented:
Applications launched from the DeskTop, or from a DOS box receive both incarnations of the message. Children don't receive the shutdown version.

Your assumtions were the same as mine, only one flag given (ENDSESSION_LOGOFF). But as it's a *flag*, it can be either set or unset. i.e. lParam could be ENDSESSION_LOGOFF or 0.

I have a feeling that I'm going to have to look for the source code for CMD.EXE etc. to get the answer. But thanks for the help.

I'll leave this question open for a little while, in case anyone has some inspiration!

0
dogmaAuthor Commented:
Adjusted points to 500
0
Tommy HuiEngineerCommented:
Here's something to try. Can you use WinExec to spawn the application? Does it make a difference? How about ShellExecute()? Another possibility would be to have a hidden application that is like a server. This server would watch for WM_ENDSESSION and sends to any children processes that it is shutting down or logging off. Of course, this introduces quite a bit of complexity, but it should be more flexible in terms of the sequence. The whole point is that you need another process under your control that catches whether the user is shutting down or logging off.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dogmaAuthor Commented:

THANKS FOR ALL YOUR HELP
However, I managed to solve the problem.
FYI:

I solved it by using a control handler (registered using SetConsoleCtrlHandler) , catching CTRL_SHUTDOWN_EVENT then using PostMessage(hWnd,WM_ENDSESSION,TRUE,0).


0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.