我有一個問題與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);
你能幫我解決這個問題嗎?
你需要做的服務的一些調試。我們無法從服務註冊碼中解決問題! –
我完成了所有可能的調試過程,服務只是不開始。並說已經提到的錯誤。 –
服務得到執行多遠?告訴我們關於迄今爲止所做的調試。你有沒有試過從你的服務中剝離掉所有的代碼,這樣它什麼都不做? –