Hi, I want to have a script which creates a windows service, and that the name of the service could be fed by user input. Example: *createservice --servicename=whatevernameichoose* * * I came out with a solution which is below:
class WindowsService(win32serviceutil.ServiceFramework): _svc_name_ = "dummyname" _svc_display_name_ = "dummydisplayname" def __init__(self, args): self.__class__._svc_name_ = args[0] win32serviceutil.ServiceFramework.__init__(self, args) # My question is not about starting and stopping service def SvcStop(self): stop_service() def SvcDoRun(self): start_service() def main(): import argparse parser = argparse.ArgumentParser() parser.add_argument('action', type=str, nargs='?') parser.add_argument('-s', type=str, nargs='?', action='store', dest='servicename', help="Name of the service to handle") cmdargs = parser.parse_args() if cmdargs.servicename: WindowsService._svc_name_ = cmdargs.servicename win32serviceutil.HandleCommandLine(WindowsService, customInstallOptions='s') if __name__=='__main__': main() As you might notice, my solution is pretty dirty. But it works, I can install and remove services with a custom name not hard coded in the script. My question is 'does someone knows a cleaner solution to achieve this ?' Cleaner would be: not override _svc_name_ dynamically, and not call another commandline parser before the one called by win32serviceutil.... As far as I understand, you can handle your customInstallOptions with a customInstallOptionsHandler, but that one is called after the creation of the service, so by that time the name of the service is already set. That's why I came out with that solution....... Thanks
_______________________________________________ python-win32 mailing list python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32