Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    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> <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> <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> <p>Here are some snippets from a service I wrote a few years ago:</p> <p>set up as service:</p> <pre><code>SERVICE_TABLE_ENTRY ServiceStartTable[] = { { "ServiceName", ServiceMain }, { 0, 0 } }; if (!StartServiceCtrlDispatcher(ServiceStartTable)) { DWORD err = GetLastError(); if (err == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) return false; } </code></pre> <p>ServiceMain:</p> <pre><code>void WINAPI ServiceMain(DWORD, LPTSTR*) { hServiceStatus = RegisterServiceCtrlHandlerEx("ServiceName", ServiceHandlerProc, 0); </code></pre> <p>service handler:</p> <pre><code>DWORD WINAPI ServiceHandlerProc(DWORD ControlCode, DWORD, void*, void*) { switch (ControlCode) { case SERVICE_CONTROL_INTERROGATE : // update OS about our status case SERVICE_CONTROL_STOP : // shut down service } return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload