Skip to content

Windows Service stops after logging-off from current user/login

Asked Aug 10, 2006, 3:52 AM EDT2 answers
Share
LinkedInX

Hi All,
        I have an EXE program which runs as a Windows Service on my Windows 2000 professional system. The programs runs fine while running as a service. The problem is that if I log off the current user, then my windows service stops. But if we refer to the SQL Server service manager, it continues to run if we log off or shutdown or restart the system. Even the actions are reflected in every login. Like if in any login we stop the SQL Server Agent, then in other login(on the same system) also the SQL Server Agent is in stopped status.

So howcome i implement this kind of functionality in my windows service.


Any help will be greatly appreciated
Thanks in advance

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Hi, I am seeing the problem with my openldap service. Did you ever get to the bottom of the problem? thanks mark
    0
  • 0
    The problem is due to the sending of a CTRL_LOGOFF_EVENT to all processes, including services on Windows! My OpenLDAP server didnt handle that event and the default behaviour on Windows is to bring the process down. I added the following to handle this event and my OpenLDAP continues to live as a service (yes, registered with SCM as it should). /** This is used to handle CTRL_LOGOFF_EVENT from shutting us down when we are running as a service. Just return TRUE and all is well. Dont really care what the event is. */ BOOL WINAPI WinSigHANDLER_ROUTINE(DWORD ctrlType) { char logstr[256]; sprintf(logstr, "NTservice: caught signal(%d)\n", ctrlType); writeStatusLog(logstr); /* switch (ctrlType) { case CTRL_LOGOFF_EVENT: ... default: } */ return TRUE; } Elsewhere in the code this handler is registered as follows: SetConsoleCtrlHandler(WinSigHANDLER_ROUTINE, TRUE);
    0