?
Solved

CreateProcess() and WM_ENDSESSION

Posted on 1998-03-04
13
Medium Priority
?
1,120 Views
Last Modified: 2013-12-03
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?
0
Comment
Question by:dogma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1411702
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
 
LVL 22

Expert Comment

by:nietod
ID: 1411703
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
 

Author Comment

by:dogma
ID: 1411704
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
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 

Author Comment

by:dogma
ID: 1411705
Edited text of question
0
 
LVL 22

Expert Comment

by:nietod
ID: 1411706
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
 

Author Comment

by:dogma
ID: 1411707
Edited text of question
0
 

Author Comment

by:dogma
ID: 1411708
Edited text of question
0
 
LVL 11

Expert Comment

by:alexo
ID: 1411709
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
 
LVL 22

Expert Comment

by:nietod
ID: 1411710
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
 

Author Comment

by:dogma
ID: 1411711
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
 

Author Comment

by:dogma
ID: 1411712
Adjusted points to 500
0
 
LVL 15

Accepted Solution

by:
Tommy Hui earned 1000 total points
ID: 1411713
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
 

Author Comment

by:dogma
ID: 1411714

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

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question