CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Why are events no longer logged after service receives SERVICE_CONTROL_SHUTDOWN?

    It took me a while to figure this one out. After my service receives SERVICE_CONTROL_SHUTDOWN notification all events that I try to log into the Windows Event Log with RegisterEventSource(), ReportEvent() APIs never get logged. Any idea why and how to enable it?

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Why are events no longer logged after service receives SERVICE_CONTROL_SHUTDOWN?

    As to me, the most probable reason is after that Event Log itself gets shut. System shutdown does not guarantee even writing to file, though you could still try that.
    Best regards,
    Igor

  3. #3
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Why are events no longer logged after service receives SERVICE_CONTROL_SHUTDOWN?

    Yes, it looks like the event logging service simply shuts down as soon as SERVICE_CONTROL_SHUTDOWN notification is sent out. I was just trying to find any official documentation that would elaborate this... But, too bad... because that is exactly the moment when logging is required...

    As for plain old CreateFile/WriteFile APIs, luckily they continue to function up until the very end. Think about it, if they stopped working there's really nothing that your service needs to do. Pretty much most of everything you do boils down to saving to a persistent storage on a low level. So not allowing it would equal to just terminating every process, wouldn't it?

  4. #4
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Why are events no longer logged after service receives SERVICE_CONTROL_SHUTDOWN?

    So not allowing it would equal to just terminating every process, wouldn't it?
    It will depend on how long it would take to write. System shutdown cannot wait endlessly, and at some point have to kill everybody still alive, just to let file system drivers shut nice.
    Best regards,
    Igor

  5. #5
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Why are events no longer logged after service receives SERVICE_CONTROL_SHUTDOWN?

    Quote Originally Posted by Igor Vartanov View Post
    It will depend on how long it would take to write. System shutdown cannot wait endlessly, and at some point have to kill everybody still alive, just to let file system drivers shut nice.
    Come on, Igor, it takes milliseconds to write. I'm not copying gigabyte files at shutdown...

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Why are events no longer logged after service receives SERVICE_CONTROL_SHUTDOWN?

    Try SERVICE_CONTROL_PRESHUTDOWN

  7. #7
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Why are events no longer logged after service receives SERVICE_CONTROL_SHUTDOWN?

    Quote Originally Posted by Arjay View Post
    Try SERVICE_CONTROL_PRESHUTDOWN
    The code has to work on XP as well.

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Why are events no longer logged after service receives SERVICE_CONTROL_SHUTDOWN?

    Quote Originally Posted by ahmd View Post
    The code has to work on XP as well.
    Code it for both. Put your hack in for XP and use PreShutdown for newer OS's.

    That way, when you quit supporting XP the hacked code goes away.

  9. #9
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Why are events no longer logged after service receives SERVICE_CONTROL_SHUTDOWN?

    Quote Originally Posted by Arjay View Post
    Code it for both. Put your hack in for XP and use PreShutdown for newer OS's.

    That way, when you quit supporting XP the hacked code goes away.
    Good point. Thank you.

    My only concern though, is it true that events will be logged from that pre-shut-down notification? Have you, or anyone else, tried it? Because I don't want to start changing it only to learn that it doesn't work there either...

  10. #10
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Why are events no longer logged after service receives SERVICE_CONTROL_SHUTDOWN?

    Quote Originally Posted by ahmd View Post
    Good point. Thank you.

    My only concern though, is it true that events will be logged from that pre-shut-down notification? Have you, or anyone else, tried it? Because I don't want to start changing it only to learn that it doesn't work there either...
    Based on the PreShutdown event description in Msdn (in your link above), it should work. You'll have to try it out, though.

  11. #11
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: Why are events no longer logged after service receives SERVICE_CONTROL_SHUTDOWN?

    I don't want to start changing it only to learn that it doesn't work there either...
    You never need to change your main project. What you need is to build a small service and fully log its behavior while shutdown proceeds. This would take you one hour (maybe two) to get all the answers that you need.
    Best regards,
    Igor

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured