<p>So creating a Windows service using Visual Studio is fairly trivial.  My question goes a bit deeper as to what actually makes an executable installable as a service &amp; how to write a service as a straight C application.  I couldn't find a lot of references on this, but I'm presuming there has to be some interface I can implement so my .exe can be installed as a service.</p>

[{'answer_id': 41706, 'author': 'Nick Berardi', 'author_id': 17, 'author_profile': 'https://Stackoverflow.com/users/17', 'pm_score': 1, 'selected': False, 'text': '<p>Hope this helps:</p>\n<p><a href="http://support.microsoft.com/kb/251192" rel="nofollow noreferrer">http://support.microsoft.com/kb/251192</a></p>\n<p>It would seem that you simple need to run this exe against a binary executable to register it as a service.</p>\n'}, {'answer_id': 41708, 'author': 'Daren Thomas', 'author_id': 2260, 'author_profile': 'https://Stackoverflow.com/users/2260', 'pm_score': 1, 'selected': False, 'text': '<p>Basically there are some registry settings you have to set as well as some interfaces to implement.</p>\n\n<p>Check out this: <a href="http://msdn.microsoft.com/en-us/library/ms685141.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms685141.aspx</a></p>\n\n<p>You are interested in the SCM (Service Control Manager).</p>\n'}, {'answer_id': 43161, 'author': 'Ferruccio', 'author_id': 4086, 'author_profile': 'https://Stackoverflow.com/users/4086', 'pm_score': 2, 'selected': False, 'text': '<p>Setting up your executable as a service is part of it, but realistically it\'s usually handled by whatever installation software you\'re using. You can use the command line SC tool while testing (or if you don\'t need an installer).</p>\n\n<p>The important thing is that your program has to call StartServiceCtrlDispatcher() upon startup. This connects your service to the service control manager and sets up a ServiceMain routine which is your services main entry point.</p>\n\n<p>ServiceMain (you can call it whatever you like actually, but it always seems to be ServiceMain) should then call RegisterServiceCtrlHandlerEx() to define a callback routine so that the OS can notify your service when certain events occur.</p>\n\n<p>Here are some snippets from a service I wrote a few years ago:</p>\n\n<p>set up as service:</p>\n\n<pre><code>SERVICE_TABLE_ENTRY ServiceStartTable[] =\n{\n   { "ServiceName", ServiceMain },\n   { 0, 0 }\n};\n\nif (!StartServiceCtrlDispatcher(ServiceStartTable))\n{\n   DWORD err = GetLastError();\n   if (err == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT)\n      return false;\n}\n</code></pre>\n\n<p>ServiceMain:</p>\n\n<pre><code>void WINAPI ServiceMain(DWORD, LPTSTR*)\n{\n    hServiceStatus = RegisterServiceCtrlHandlerEx("ServiceName", ServiceHandlerProc, 0);\n</code></pre>\n\n<p>service handler:</p>\n\n<pre><code>DWORD WINAPI ServiceHandlerProc(DWORD ControlCode, DWORD, void*, void*)\n{\n    switch (ControlCode)\n    {\n    case SERVICE_CONTROL_INTERROGATE :\n        // update OS about our status\n    case SERVICE_CONTROL_STOP :\n        // shut down service\n    }\n\n    return 0;\n}\n</code></pre>\n'}, {'answer_id': 1195001, 'author': 'KevenK', 'author_id': 103825, 'author_profile': 'https://Stackoverflow.com/users/103825', 'pm_score': 1, 'selected': False, 'text': '<p>I know I\'m a bit late to the party, but I\'ve recently had this same question, and had to struggle through the interwebs looking for answers.</p>\n\n<p>I managed to find this article in MSDN that does in fact lay the groundwork. I ended up combining many of the files here into a single exe that contains all of the commands I need, and added in my own "void run()" method that loops for the entirely life of the service for my own needs.</p>\n\n<p>This would be a great start to someone else with exactly this question, so for future searchers out there, check it out:</p>\n\n<p><strong>The Complete Service Sample</strong>\n<a href="http://msdn.microsoft.com/en-us/library/bb540476(VS.85).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/bb540476(VS.85).aspx</a></p>\n'}]
['https://Stackoverflow.com/questions/41699', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/634/']