Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is how we handled this situation. This code was added to our main service class and then at the point where we wanted to return startup as failed, made a call to SetServiceFail(1065) followed by a return from OnStart. In this case 1065 returns a database does not exist status.</p> <p>I would also note that in SetServiceFail I hard-coded the serviceType since in our case all of our services are stand-alone so I kept it simple.</p> <pre><code>private void SetServiceFail (int ErrorCode) { SERVICE_STATUS _ServiceStatus = new SERVICE_STATUS (); _ServiceStatus.currentState = (int) State.SERVICE_STOPPED; _ServiceStatus.serviceType = 16; //SERVICE_WIN32_OWN_PROCESS _ServiceStatus.waitHint = 0; _ServiceStatus.win32ExitCode = ErrorCode; _ServiceStatus.serviceSpecificExitCode = 0; _ServiceStatus.checkPoint = 0; _ServiceStatus.controlsAccepted = 0 | (this.CanStop ? (int) ControlsAccepted.ACCEPT_STOP : 0) | (this.CanShutdown ? (int) ControlsAccepted.ACCEPT_SHUTDOWN : 0) | (this.CanPauseAndContinue ? (int) ControlsAccepted.ACCEPT_PAUSE_CONTINUE : 0) | (this.CanHandleSessionChangeEvent ? (int) ControlsAccepted.ACCEPT_SESSION_CHANGE : 0) | (this.CanHandlePowerEvent ? (int) ControlsAccepted.ACCEPT_POWER_EVENT : 0); SetServiceStatus (this.ServiceHandle, ref _ServiceStatus); } public enum State { SERVICE_STOPPED = 1, SERVICE_START_PENDING = 2, SERVICE_STOP_PENDING = 3, SERVICE_RUNNING = 4, SERVICE_CONTINUE_PENDING = 5, SERVICE_PAUSE_PENDING = 6, SERVICE_PAUSED = 7 } public enum ControlsAccepted { ACCEPT_STOP = 1, ACCEPT_PAUSE_CONTINUE = 2, ACCEPT_SHUTDOWN = 4, ACCEPT_POWER_EVENT = 64, ACCEPT_SESSION_CHANGE = 128 } [StructLayout (LayoutKind.Sequential)] private struct SERVICE_STATUS { public int serviceType; public int currentState; public int controlsAccepted; public int win32ExitCode; public int serviceSpecificExitCode; public int checkPoint; public int waitHint; } [DllImport ("advapi32.dll")] private static extern bool SetServiceStatus (IntPtr hServiceStatus, ref SERVICE_STATUS lpServiceStatus); </code></pre>
    singulars
    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.
    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