1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Rep Power

    Talking problems with running services under windowsXP

    I have developed an application (server using sockets). It works fine but now I tried to change the application to be run as a server.
    Now this works fine as well as long as I use Windows NT or Windows 2000 for the operating system.
    The problem is, that the application does not start as a service running an windows XP.

    Here is my ServiceMain procedure:

    void WINAPI ServiceMain( DWORD /*argc*/, TCHAR* /*argv*/[] )
    Beep( 1000, 100 );
    // initialise service status
    serviceStatus.dwServiceType = SERVICE_WIN32;
    serviceStatus.dwCurrentState = SERVICE_STOPPED;
    serviceStatus.dwControlsAccepted = 0;
    serviceStatus.dwWin32ExitCode = NO_ERROR;
    serviceStatus.dwServiceSpecificExitCode = NO_ERROR;
    serviceStatus.dwCheckPoint = 0;
    serviceStatus.dwWaitHint = 30000;

    serviceStatusHandle = RegisterServiceCtrlHandler( serviceName, ServiceControlHandler );

    if ( serviceStatusHandle )
    // service is starting
    serviceStatus.dwCurrentState = SERVICE_START_PENDING;
    SetServiceStatus( serviceStatusHandle, &serviceStatus );

    // do initialisation here
    stopServiceEvent = CreateEvent( 0, FALSE, FALSE, "VCWSERVER_CTRL_C_E" );

    // running
    serviceStatus.dwControlsAccepted |= (SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN);
    serviceStatus.dwCurrentState = SERVICE_RUNNING;
    SetServiceStatus( serviceStatusHandle, &serviceStatus );
    AddToMessageLog("VCWServer started", EVENTLOG_INFORMATION_TYPE );



    // service was stopped
    serviceStatus.dwCurrentState = SERVICE_STOP_PENDING;
    SetServiceStatus( serviceStatusHandle, &serviceStatus );

    // do cleanup here
    CloseHandle( stopServiceEvent );
    stopServiceEvent = 0;

    // service is now stopped
    serviceStatus.dwControlsAccepted &= ~(SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN);
    serviceStatus.dwCurrentState = SERVICE_STOPPED;
    SetServiceStatus( serviceStatusHandle, &serviceStatus );
    AddToMessageLog("VCWServer stopped", EVENTLOG_INFORMATION_TYPE );

    Here is the registration of the service at the service control manager:

    void RunService(int mode) {
    if (mode==0) {
    SERVICE_TABLE_ENTRY serviceTable[] =
    { serviceName, ServiceMain },
    { 0, 0 }

    if (!StartServiceCtrlDispatcher( serviceTable )) {
    AddToMessageLog("StartServiceCtrlDispatcher failed", EVENTLOG_ERROR_TYPE );

    The method StartServiceCtrlDispatcher seems to make problems under windows XP -> The ErrorMessage is something like:

    "The service did not respond on time to the request of the service control manager".

    Another weird thing is, that my program does not react in any way to a CTRL+C if I run it in console mode (not as a service).
    I was expecting to get a signal "CTRL+C" but it simply is not created by the system, while the "CTRL+BREAK" Signal seems to work fine.

    Thanx a lot for your help in advance!


  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Rep Power
    Just a quick stupid question, since I am blessed with not having to work with XP:
    Do you need to have administrator rights to run a service on XP? You might also want to add error-checking to verify that certain key function calls did succeed and to see what kinds of errors are generated.

    You might also want to post your question on CodeGuru at http://www.codeguru.com/forum/ . They concentrate much more on Microsoft development environments and Windows programming, whereas this group is more generally C/C++.

IMN logo majestic logo threadwatch logo seochat tools logo