You'd simply need to override GetAcceptedControls() in your
ServiceFramework subclass to OR in SERVICE_ACCEPT_PRESHUTDOWN and override
SvcOtherEx to process SERVICE_CONTROL_PRESHUTDOWN.

Other interesting service control notifications appear to be PowerEvent and
TimeChange. I'd guess PowerEvent is for sleep/hibernation, and TimeChange
is to deal with time jumping forward and backward on you. (via NTP or
manual intervention)

Here are the constants to use:

#define SERVICE_CONTROL_PRESHUTDOWN            0x0000000F
#define SERVICE_ACCEPT_PRESHUTDOWN             0x00000100

Bill


On Tue, Feb 7, 2012 at 1:54 AM, Mark Hammond <skippy.hamm...@gmail.com>wrote:

> On 7/02/2012 5:18 PM, Lincoln Yeoh wrote:
>
>> Hi,
>>
>> Is it easy to create a python windows service that registers for the
>> preshutdown event[1]?
>>
>
> It sounds like it should be easy, although you will need to define your
> own new constants which have been introduced.  It would be great if you do
> get it working you contribute a working sample which I can add to pywin32.
>
> Cheers,
>
> Mark
>
>
>
>> Basically I would like a window service that will help shutdown .Net
>> (and possibly other) services in the right order.
>>
>> Because:
>> http://connect.microsoft.com/**VisualStudio/feedback/details/**
>> 641737/add-windows-service-**preshutdown<http://connect.microsoft.com/VisualStudio/feedback/details/641737/add-windows-service-preshutdown>
>>
>> "A Windows service in C# cannot be registered to preshutdown
>> notifications. It is possible in C++ but not in C# with the current .net
>> framework"
>>
>> http://support.microsoft.com/**kb/203878<http://support.microsoft.com/kb/203878>
>>
>> "When a service is dependendent on other services, the Service Control
>> Manager (SCM) will automatically start the dependencies before starting
>> the dependent service itself. However, during system shutdown, the SCM
>> does not take dependencies into consideration when stopping services. It
>> simply enumerates the list of running services and sends a
>> SERVICE_CONTROL_SHUTDOWN command to all of them. Thus, a service may
>> stop responding or fail because another service it depends upon has
>> already stopped."
>>
>> (yeah weird right?)
>>
>> And, since I'm a crappy and lazy programmer I think it'll be easier for
>> me to write such a thing in Python than C++, reasonably quickly, with
>> the features I want and with not too many bugs.
>>
>> Regards,
>>
>> Link.
>>
>> [1] 
>> http://msdn.microsoft.com/en-**us/magazine/cc164252.aspx#S2<http://msdn.microsoft.com/en-us/magazine/cc164252.aspx#S2>
>>
>> ______________________________**_________________
>> python-win32 mailing list
>> python-win32@python.org
>> http://mail.python.org/**mailman/listinfo/python-win32<http://mail.python.org/mailman/listinfo/python-win32>
>>
>
> ______________________________**_________________
> python-win32 mailing list
> python-win32@python.org
> http://mail.python.org/**mailman/listinfo/python-win32<http://mail.python.org/mailman/listinfo/python-win32>
>
>
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32

Reply via email to