我有一个问题与Windows服务,我的应用程序注册的Windows服务,但是当我试图跑,我发现了以下错误的服务:“错误1053:服务没有没有及时响应启动或控制请求“。以下代码负责注册服务(我从MSDN获得它)。问题与Windows服务(C++,WinAPI的)
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);
你能帮我解决这个问题吗?
你需要做的服务的一些调试。我们无法从服务注册码中解决问题! –
我完成了所有可能的调试过程,服务只是不开始。并说已经提到的错误。 –
服务得到执行多远?告诉我们关于迄今为止所做的调试。你有没有试过从你的服务中剥离掉所有的代码,这样它什么都不做? –