Thread: Starting a Service

  1. #1
    Registered User
    Join Date
    Dec 2004
    Location
    The Netherlands
    Posts
    91

    Starting a Service

    Hi,

    I am trying to install an application as a service. I have managed to install itself, it can be seen in services.msc. However, for some reason I cannot start the service, GetLastError keeps returning 1053 (ERROR_SERVICE_REQUEST_TIMEOUT The service did not respond to the start or control request in a timely fashion.).

    Here is the part that tries to start the service:
    Code:
    if(StartService(OpenService(OpenSCManager( 0, 0, SC_MANAGER_CONNECT),"Test Service",SERVICE_ALL_ACCESS),0, NULL) != 0) 
    	printf("Started Successfully!\n");
    else printf("Error->[%d]\n", GetLastError());
    Any tips and help would be appreciated.

  2. #2
    Registered User
    Join Date
    Dec 2004
    Location
    The Netherlands
    Posts
    91
    Hmm, when I try to activate the service manually via services.msc I get the same return error, so I guess there isnt anything wrong with the code but my system... Maybe because I put calc.exe as filename to test, is that even possible?

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    of course you cannot start calc.exe as a service - this exe does not have corresponding starting point that the StartService is looking for...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  4. #4
    Registered User
    Join Date
    Dec 2004
    Location
    The Netherlands
    Posts
    91
    Ah, didnt know that, are executables that run as services different than normal binary files..

  5. #5
    Registered User
    Join Date
    Mar 2005
    Location
    Mountaintop, Pa
    Posts
    1,058
    are executables that run as services different than normal binary files
    Yes, a console service main function is very basic. It calls StartServiceCtrlDispatcher to connect the main thread of your service to the Service Control Manager. This is accomplished by completing the SERVICE_TABLE_ENTRY structure and calling StartServiceCtrlDispatcher and passing the SERVICE_TABLE_ENTRY structure as a parm. Your stock executables such as calc.exe do not connect to the SCM in this manner at all. Thus, they cannot be run as services.

  6. #6
    Registered User
    Join Date
    Dec 2004
    Location
    The Netherlands
    Posts
    91
    Ah, that makes sense, thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. running my program as service
    By daher in forum Windows Programming
    Replies: 5
    Last Post: 09-05-2008, 12:30 PM
  2. Windows service status checking
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 06-01-2008, 08:19 AM
  3. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  4. Starting a NT service through an application?
    By crazyfish in forum Windows Programming
    Replies: 2
    Last Post: 06-06-2005, 10:56 PM
  5. Another windows service question... starting/stopping
    By BrianK in forum Windows Programming
    Replies: 1
    Last Post: 03-20-2003, 12:22 AM