[python-win32] Re: How to determine whether program running asservice?

Thomas Heller theller at python.net
Fri Sep 10 13:48:16 CEST 2004


"Mark Hammond" <mhammond at skippinet.com.au> writes:

>> >> I don't see one :(  I would be happy to add one  - eg,
>> >> sys.serviceexecutable being set to the host executable when
>> >> launched as a service.
>>
>> Is it possible to determine that a process is launched as service?  I
>> don't think there is one, at least I didn't find one.
>
> No direct way I found - but service_main() could set a flag - this code
> knows for certain it is running as a service (or for debugging).
>
> Thinking about it a bit more - since this code exists in servicemanager.pyd,
> it makes the most sense for servicemanager.pyd itself to have these
> attributes.
>
> servicemanager.is_service = boolean
> servicemanager.is_debugging = boolean
>
> That shouldn't be too hard to setup.  'serviceexecutable' is a bit silly,
> but it kinda made sense given the various other sys.dll/executable variables
> used.  But keeping it out of sys makes far more sense.

I'm not sure I really understand, and don't have time too look into the
code right now.

Would it be possible with these changes to have code like this at the
end of py2exe's boot_service.py:

"""
if launched_as_service:
    servicemanager.StartServiceControlDispatcher()
"""

so that the StartServiceControlDispatcher is not called when the service
exe is started manually by the user?

Thomas



More information about the Python-win32 mailing list