[python-win32] Windows Service Parameters

Mark Hammond mhammond at skippinet.com.au
Fri Apr 7 03:26:06 CEST 2006

> Hello,
> Does anybody have an example of getting hold of the "start parameters"
> in a Python windows service?
> I was half expecting them to be passed to SvcDoRun but I can't see
> that they are.

Not an example - but they are passed to your service's __init__ function.
Most of the examples don't show that - so you need:

class MyService(win32serviceutil.ServiceFramework):
  def __init__(self, args):
    win32serviceutil.ServiceFramework.__init__(self, args)
    # use args - args[0] is the "service name"

Also note that no one persists these service arguments - so entering them
into the service manager means they get passed as you start the service that
once - they will not be passed in the future as the serivce starts normally.

For this reason it is common for your code to write the args to the registry
so you can see them next time.  win32serviceutil.Set/GetServiceCustomOption
may help (but obviously you can persist them any way you choose)


More information about the Python-win32 mailing list