<p>In <a href="https://stackoverflow.com/questions/32404/can-i-run-a-python-script-as-a-service-in-windows-how" title="Python scripts as Windows service">another question</a> I posted yesterday, I got very good advice on how a Python script could be run as a service in Windows. What I'm left wondering is: How is Windows aware of the services that can be managed in the native tools ("services" window in "administrative tools"). I. e. what is the Windows equivalent of putting a start/stop script in /etc/init.d under Linux?</p>

[{'answer_id': 34330, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 3, 'selected': False, 'text': '<p>Here is code to install a python-script as a service, written in python :)</p>\n\n<p><a href="http://code.activestate.com/recipes/551780/" rel="noreferrer">http://code.activestate.com/recipes/551780/</a></p>\n\n<p>This post could also help you out:</p>\n\n<p><a href="http://essiene.blogspot.com/2005/04/python-windows-services.html" rel="noreferrer">http://essiene.blogspot.com/2005/04/python-windows-services.html</a></p>\n'}, {'answer_id': 34418, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 3, 'selected': True, 'text': '<p>As with most "aware" things in Windows, the answer is "Registry".</p>\n\n<p>Take a look at this Microsoft Knowledge Base article: <a href="http://support.microsoft.com/kb/103000" rel="nofollow noreferrer">http://support.microsoft.com/kb/103000</a></p>\n\n<p>Search for "A Win32 program that can be started by the Service Controller and that obeys the service control protocol." This is the kind of service you\'re interested in.</p>\n\n<p>The service registration (contents of KEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Services\n\\myservice) carries information about the service, including things like its executable location, what to do when it fails (halt the OS?), what services must be started before this one, what user it runs as.</p>\n\n<p>As to service control protocol, main() of your program is supposed to invoke a Windows API call, setting up callbacks for start, stop, pause for your service. What you do in those callbacks is all up to you.</p>\n'}, {'answer_id': 34421, 'author': 'mmattax', 'author_id': 1638, 'author_profile': 'https://Stackoverflow.com/users/1638', 'pm_score': 0, 'selected': False, 'text': '<p>You can use srvany.exe from Windows NT Resource Kit to create a user defined service that will show up in the admin tools...</p>\n\n<p><a href="http://support.microsoft.com/kb/137890" rel="nofollow noreferrer">http://support.microsoft.com/kb/137890</a></p>\n\n<p>I am using this method to run tracd (a python script / server) for trac. </p>\n\n<p>Here are some very clear instructions: <a href="http://www.tacktech.com/display.cfm?ttid=197" rel="nofollow noreferrer">http://www.tacktech.com/display.cfm?ttid=197</a></p>\n\n<p>It does require some registry editing (very minimal and easy) but will allow you to make any command line / script a windows service. </p>\n'}, {'answer_id': 259438, 'author': 'Ferruccio', 'author_id': 4086, 'author_profile': 'https://Stackoverflow.com/users/4086', 'pm_score': 3, 'selected': False, 'text': '<p>Don\'t muck with the registry directly. User the SC command-line tool. Namely, SC CREATE</p>\n\n<pre>\n    DESCRIPTION:\n        SC is a command line program used for communicating with the\n        NT Service Controller and services.\n    USAGE:\n        sc  [command] [service name]  ...\n\n        The option  has the form "\\\\ServerName"\n        Further help on commands can be obtained by typing: "sc [command]"\n        Commands:\n          query-----------Queries the status for a service, or\n                          enumerates the status for types of services.\n          queryex---------Queries the extended status for a service, or\n                          enumerates the status for types of services.\n          start-----------Starts a service.\n          pause-----------Sends a PAUSE control request to a service.\n          interrogate-----Sends an INTERROGATE control request to a service.\n          continue--------Sends a CONTINUE control request to a service.\n          stop------------Sends a STOP request to a service.\n          config----------Changes the configuration of a service (persistant).\n          description-----Changes the description of a service.\n          failure---------Changes the actions taken by a service upon failure.\n          qc--------------Queries the configuration information for a service.\n          qdescription----Queries the description for a service.\n          qfailure--------Queries the actions taken by a service upon failure.\n          delete----------Deletes a service (from the registry).\n          create----------Creates a service. (adds it to the registry).\n          control---------Sends a control to a service.\n          sdshow----------Displays a service\'s security descriptor.\n          sdset-----------Sets a service\'s security descriptor.\n          GetDisplayName--Gets the DisplayName for a service.\n          GetKeyName------Gets the ServiceKeyName for a service.\n          EnumDepend------Enumerates Service Dependencies.\n\n        The following commands don\'t require a service name:\n        sc   \n          boot------------(ok | bad) Indicates whether the last boot should\n                          be saved as the last-known-good boot configuration\n          Lock------------Locks the Service Database\n          QueryLock-------Queries the LockStatus for the SCManager Database\n    EXAMPLE:\n        sc start MyService\n</pre>\n'}]
['https://Stackoverflow.com/questions/34328', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2077/']