Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6859781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:19:34+00:00 2026-05-27T02:19:34+00:00

I have an issue with windows services, my application registering Windows service but when

  • 0

I have an issue with windows services, my application registering Windows service but when I’m trying to run the service I’m getting the following error: “Error 1053: The service did not respond to the start or control request in a timely fashion”. The following code is responsible for registering service (I’ve got it from MSDN).

SC_HANDLE schSCManager;
SC_HANDLE schService;

path modulePath("some path to executable");

std::string moduleName = narrow(modulePath.native());

if(!GetModuleFileNameA(NULL, &moduleName[0], MAX_PATH))
{
 throw std::runtime_error("Cannot register service, error code: " +    boost::lexical_cast<std::string>(GetLastError()));
}

// Get a handle to the SCM database. 
   schSCManager = OpenSCManager(NULL,                   // local computer
                                NULL,                   // ServicesActive database 
                                SC_MANAGER_ALL_ACCESS); // full access rights 

   if(!schSCManager) 
   {
      throw std::runtime_error("OpenSCManager failed: " + boost::lexical_cast<std::string>(GetLastError()));
   }

   // Create the service
   schService = CreateServiceA( 
        schSCManager,              // SCM database 
        "name",                  // name of service 
        "displayname",                  // service name to display 
        SERVICE_ALL_ACCESS,        // desired access 
        SERVICE_WIN32_OWN_PROCESS, // service type 
        SERVICE_AUTO_START,        // start type 
        SERVICE_ERROR_NORMAL,      // error control type 
        narrow(modulePath.native()).c_str(), // path to service's binary 
        NULL,                      // no load ordering group 
        NULL,                      // no tag identifier 
        NULL,                      // no dependencies 
        NULL,                      // LocalSystem account 
        NULL);                     // no password 

   if(!schService) 
   {
      CloseServiceHandle(schSCManager);

      throw std::runtime_error("CreateService failed: " + boost::lexical_cast<std::string>(GetLastError()));
   }
   else
   {
      //std::cout << "\nService installed successfully\n";
   } 

   CloseServiceHandle(schService); 
   CloseServiceHandle(schSCManager);   

Could you please help to fix this ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:19:35+00:00Added an answer on May 27, 2026 at 2:19 am

    In case the given code is the only thing you tried you’re missing some important requirements for a windows service. Please have a look at the documentation

    You need at least a service main function (wich is different from the main method!) and a control handler function as you can’t handle the “start” command if there’s no control handler function registered (wich is done in service main)

    In order to work properly you need:

    1. the ordinary main method, to determine if you want to install the service or to otherwise start the service control dispatcher with the services SERVICE_TABLE_ENTRY
      this table contains baiscally the process name and the function pointer to it’s service main function
    2. you need the service main function wich registeres the functions service control handler function and afterwards starts the service code function
    3. the service code function contains the code related to the services job, it’s the heart of the service
    4. you need the service control hander function. it is called from windows’ service control manager, whenever a control code is sent to the service… this is the method that receives the “stop” command… and if this function doesn’t exists or isn’t registered properly you might end up with an error like the one mentioned…
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following issue: I'm introducing new feature into application (run as Windows Service)
In our application, we have a number of Windows Services (more than 30) that
I have an x86 Windows application that consists of a couple of services and
I have a Windows Service that does the following when started. When running via
I have a windows service running as part of my application. If I wish
I have a .NET 3.5 Windows Service. I'm testing with a small application that
I have an issue with a Windows Forms application that I am creating. The
i'm ASP.NET programmer and have no experience in creating windows services. Service i need
We have an issue using the PEAR libraries on Windows from PHP . Pear
I have found an interesting issue in windows which allows me to cause the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.