Starting a Service

This is a discussion on Starting a Service within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I am trying to install an application as a service. I have managed to install itself, it can be ...

  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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,456
    of course you cannot start calc.exe as a service - this exe does not have corresponding starting point that the StartService is looking for...
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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,059
    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-19-2003, 11:22 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21