Getting problem in writing windows service [ ERROR 1053 ] [modified]
-
I am using visual studio 2005 and i am trying to write a windows service which will basically check whether a particular exe is running or not. I have down loaded a sample code and created a service called "Service1" and i am able to successfully install and uninstall the service in to my windows XP machine with service pack 2. Problem: I cant start the service from the win service list and i am getting an error message as below. Could not start service on the local system. ERROR 1053:The service did not respond to the start or control request in a timely fashion. Below is my service code
#include "stdafx.h" #include "Windows.h" #include "Winsvc.h" #include "time.h" #include "tlhelp32.h" SERVICE_STATUS m_ServiceStatus; SERVICE_STATUS_HANDLE m_ServiceStatusHandle; BOOL bRunning=true; void WINAPI ServiceMain(DWORD argc, LPTSTR *argv); void WINAPI ServiceCtrlHandler(DWORD Opcode); BOOL InstallService(); BOOL DeleteService(); bool isExeRunning(WCHAR *zExeName, bool *pbRunning); int main(int argc, char* argv[]) { if(argc>1) { if(strcmp(argv[1],"-i")==0) { if(InstallService()) printf("\n\nService Installed Sucessfully\n"); else printf("\n\nError Installing Service\n"); } if(strcmp(argv[1],"-d")==0) { if(DeleteService()) printf("\n\nService UnInstalled Sucessfully\n"); else printf("\n\nError UnInstalling Service\n"); } else { printf("\n\nUnknown Switch Usage\n\nFor Install use Srv1 -i\n\nFor UnInstall use Srv1 -d\n"); } } else { SERVICE_TABLE_ENTRY DispatchTable[]={{L"PointService",ServiceMain},{NULL,NULL}}; StartServiceCtrlDispatcher(DispatchTable); } return 0; } void WINAPI ServiceMain(DWORD argc, LPTSTR *argv) { m_ServiceStatus.dwServiceType = SERVICE_WIN32; m_ServiceStatus.dwCurrentState = SERVICE_START_PENDING; m_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; m_ServiceStatus.dwWin32ExitCode = 0; m_ServiceStatus.dwServiceSpecificExitCode = 0; m_ServiceStatus.dwCheckPoint = 0; m_ServiceStatus.dwWaitHint = 0; m_ServiceStatusHandle = RegisterServiceCtrlHandler(L"PointService", ServiceCtrlHandler); if (m_ServiceStatusHandle == (SERVICE_STATUS_HANDLE)0) { return; } m_ServiceStatus.dwCurrentState = SERVICE_RUNNING; m_ServiceStatus.dwCheckPoint = 0; m_ServiceStatus.dwWaitHint = 0; if (!SetServiceStatus (m_ServiceStatusHandle, &m_ServiceStatus)) { } bRunning=true; while(bRunning) { Sleep(3000);
-
I am using visual studio 2005 and i am trying to write a windows service which will basically check whether a particular exe is running or not. I have down loaded a sample code and created a service called "Service1" and i am able to successfully install and uninstall the service in to my windows XP machine with service pack 2. Problem: I cant start the service from the win service list and i am getting an error message as below. Could not start service on the local system. ERROR 1053:The service did not respond to the start or control request in a timely fashion. Below is my service code
#include "stdafx.h" #include "Windows.h" #include "Winsvc.h" #include "time.h" #include "tlhelp32.h" SERVICE_STATUS m_ServiceStatus; SERVICE_STATUS_HANDLE m_ServiceStatusHandle; BOOL bRunning=true; void WINAPI ServiceMain(DWORD argc, LPTSTR *argv); void WINAPI ServiceCtrlHandler(DWORD Opcode); BOOL InstallService(); BOOL DeleteService(); bool isExeRunning(WCHAR *zExeName, bool *pbRunning); int main(int argc, char* argv[]) { if(argc>1) { if(strcmp(argv[1],"-i")==0) { if(InstallService()) printf("\n\nService Installed Sucessfully\n"); else printf("\n\nError Installing Service\n"); } if(strcmp(argv[1],"-d")==0) { if(DeleteService()) printf("\n\nService UnInstalled Sucessfully\n"); else printf("\n\nError UnInstalling Service\n"); } else { printf("\n\nUnknown Switch Usage\n\nFor Install use Srv1 -i\n\nFor UnInstall use Srv1 -d\n"); } } else { SERVICE_TABLE_ENTRY DispatchTable[]={{L"PointService",ServiceMain},{NULL,NULL}}; StartServiceCtrlDispatcher(DispatchTable); } return 0; } void WINAPI ServiceMain(DWORD argc, LPTSTR *argv) { m_ServiceStatus.dwServiceType = SERVICE_WIN32; m_ServiceStatus.dwCurrentState = SERVICE_START_PENDING; m_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; m_ServiceStatus.dwWin32ExitCode = 0; m_ServiceStatus.dwServiceSpecificExitCode = 0; m_ServiceStatus.dwCheckPoint = 0; m_ServiceStatus.dwWaitHint = 0; m_ServiceStatusHandle = RegisterServiceCtrlHandler(L"PointService", ServiceCtrlHandler); if (m_ServiceStatusHandle == (SERVICE_STATUS_HANDLE)0) { return; } m_ServiceStatus.dwCurrentState = SERVICE_RUNNING; m_ServiceStatus.dwCheckPoint = 0; m_ServiceStatus.dwWaitHint = 0; if (!SetServiceStatus (m_ServiceStatusHandle, &m_ServiceStatus)) { } bRunning=true; while(bRunning) { Sleep(3000);
ERROR_SERVICE_REQUEST_TIMEOUT: The process for the service was started, but it did not call StartServiceCtrlDispatcher, or the thread that called StartServiceCtrlDispatcher may be blocked in a control handler function.
Soumyadipta wrote:
ServiceMain(NULL,NULL);
I suspect this one, servicemain is called by SCM. you are calling Service main in the service program main, this shows you have little knowledge about it or may be me. [How to debug Windows services^]
-
I am using visual studio 2005 and i am trying to write a windows service which will basically check whether a particular exe is running or not. I have down loaded a sample code and created a service called "Service1" and i am able to successfully install and uninstall the service in to my windows XP machine with service pack 2. Problem: I cant start the service from the win service list and i am getting an error message as below. Could not start service on the local system. ERROR 1053:The service did not respond to the start or control request in a timely fashion. Below is my service code
#include "stdafx.h" #include "Windows.h" #include "Winsvc.h" #include "time.h" #include "tlhelp32.h" SERVICE_STATUS m_ServiceStatus; SERVICE_STATUS_HANDLE m_ServiceStatusHandle; BOOL bRunning=true; void WINAPI ServiceMain(DWORD argc, LPTSTR *argv); void WINAPI ServiceCtrlHandler(DWORD Opcode); BOOL InstallService(); BOOL DeleteService(); bool isExeRunning(WCHAR *zExeName, bool *pbRunning); int main(int argc, char* argv[]) { if(argc>1) { if(strcmp(argv[1],"-i")==0) { if(InstallService()) printf("\n\nService Installed Sucessfully\n"); else printf("\n\nError Installing Service\n"); } if(strcmp(argv[1],"-d")==0) { if(DeleteService()) printf("\n\nService UnInstalled Sucessfully\n"); else printf("\n\nError UnInstalling Service\n"); } else { printf("\n\nUnknown Switch Usage\n\nFor Install use Srv1 -i\n\nFor UnInstall use Srv1 -d\n"); } } else { SERVICE_TABLE_ENTRY DispatchTable[]={{L"PointService",ServiceMain},{NULL,NULL}}; StartServiceCtrlDispatcher(DispatchTable); } return 0; } void WINAPI ServiceMain(DWORD argc, LPTSTR *argv) { m_ServiceStatus.dwServiceType = SERVICE_WIN32; m_ServiceStatus.dwCurrentState = SERVICE_START_PENDING; m_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; m_ServiceStatus.dwWin32ExitCode = 0; m_ServiceStatus.dwServiceSpecificExitCode = 0; m_ServiceStatus.dwCheckPoint = 0; m_ServiceStatus.dwWaitHint = 0; m_ServiceStatusHandle = RegisterServiceCtrlHandler(L"PointService", ServiceCtrlHandler); if (m_ServiceStatusHandle == (SERVICE_STATUS_HANDLE)0) { return; } m_ServiceStatus.dwCurrentState = SERVICE_RUNNING; m_ServiceStatus.dwCheckPoint = 0; m_ServiceStatus.dwWaitHint = 0; if (!SetServiceStatus (m_ServiceStatusHandle, &m_ServiceStatus)) { } bRunning=true; while(bRunning) { Sleep(3000);
That was a silly mistake. I have corrected the code but still i am getting the same problem. Also i have downloaded the FirstService.zip from code project which is also giving me the same error message.
-
That was a silly mistake. I have corrected the code but still i am getting the same problem. Also i have downloaded the FirstService.zip from code project which is also giving me the same error message.
It would help you to get an answer if you read the "how to get help" message at the front of the forum, and use the pre tag to enclose your code, not the code tag. pre preserves the spacing and indentation to make it easier for people to read your code. If we have to to struggle through a wall of text, we'll give up, and you won;t get assistance... Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
-
It would help you to get an answer if you read the "how to get help" message at the front of the forum, and use the pre tag to enclose your code, not the code tag. pre preserves the spacing and indentation to make it easier for people to read your code. If we have to to struggle through a wall of text, we'll give up, and you won;t get assistance... Iain.
Plz sir... CPallini CPallini abuz drugz, plz plz help urgent.
The problem is now solved.I have separated the installer code block from the existing code and have created a separate exe to install the service.I don't know the reason why the installer code block was creating the probel of ERROR 1053. Below is the installer code:
/* A console program that installs our skeleton service */ /* Author :- Nishant S */ /* EMail :- nish@inapp.com */ #include #include #include void ShowErr(); int main(int argc, char* argv[]) { SC_HANDLE NishService,scm; scm=OpenSCManager(0,0,SC_MANAGER_CREATE_SERVICE); if(!scm) { ShowErr(); return 1; } NishService=CreateService(scm,"PointHDListener", "PointHDListener Service", SERVICE_ALL_ACCESS,SERVICE_WIN32_OWN_PROCESS,SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, "D:\\Service1.exe", 0,0,0,0,0); if(!NishService) { CloseServiceHandle(scm); ShowErr(); return 1; } CloseServiceHandle(NishService); CloseServiceHandle(scm); return 0; } void ShowErr() { //cout << "Error" << "\r\n"; }
-
I am using visual studio 2005 and i am trying to write a windows service which will basically check whether a particular exe is running or not. I have down loaded a sample code and created a service called "Service1" and i am able to successfully install and uninstall the service in to my windows XP machine with service pack 2. Problem: I cant start the service from the win service list and i am getting an error message as below. Could not start service on the local system. ERROR 1053:The service did not respond to the start or control request in a timely fashion. Below is my service code
#include "stdafx.h" #include "Windows.h" #include "Winsvc.h" #include "time.h" #include "tlhelp32.h" SERVICE_STATUS m_ServiceStatus; SERVICE_STATUS_HANDLE m_ServiceStatusHandle; BOOL bRunning=true; void WINAPI ServiceMain(DWORD argc, LPTSTR *argv); void WINAPI ServiceCtrlHandler(DWORD Opcode); BOOL InstallService(); BOOL DeleteService(); bool isExeRunning(WCHAR *zExeName, bool *pbRunning); int main(int argc, char* argv[]) { if(argc>1) { if(strcmp(argv[1],"-i")==0) { if(InstallService()) printf("\n\nService Installed Sucessfully\n"); else printf("\n\nError Installing Service\n"); } if(strcmp(argv[1],"-d")==0) { if(DeleteService()) printf("\n\nService UnInstalled Sucessfully\n"); else printf("\n\nError UnInstalling Service\n"); } else { printf("\n\nUnknown Switch Usage\n\nFor Install use Srv1 -i\n\nFor UnInstall use Srv1 -d\n"); } } else { SERVICE_TABLE_ENTRY DispatchTable[]={{L"PointService",ServiceMain},{NULL,NULL}}; StartServiceCtrlDispatcher(DispatchTable); } return 0; } void WINAPI ServiceMain(DWORD argc, LPTSTR *argv) { m_ServiceStatus.dwServiceType = SERVICE_WIN32; m_ServiceStatus.dwCurrentState = SERVICE_START_PENDING; m_ServiceStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP; m_ServiceStatus.dwWin32ExitCode = 0; m_ServiceStatus.dwServiceSpecificExitCode = 0; m_ServiceStatus.dwCheckPoint = 0; m_ServiceStatus.dwWaitHint = 0; m_ServiceStatusHandle = RegisterServiceCtrlHandler(L"PointService", ServiceCtrlHandler); if (m_ServiceStatusHandle == (SERVICE_STATUS_HANDLE)0) { return; } m_ServiceStatus.dwCurrentState = SERVICE_RUNNING; m_ServiceStatus.dwCheckPoint = 0; m_ServiceStatus.dwWaitHint = 0; if (!SetServiceStatus (m_ServiceStatusHandle, &m_ServiceStatus)) { } bRunning=true; while(bRunning) { Sleep(3000);
How can i display a window message from my service? I am able to create and install a windows service. I am beeping a sound from my service successfully. Now i want to display a message when some event occurs.Basically in my code i am looking for a exe and checking whether it is running or not. I want to display a message "Exe not running or started/ Crashed due to some error" from my service when i found the exe is not running means when status=false.
-
The problem is now solved.I have separated the installer code block from the existing code and have created a separate exe to install the service.I don't know the reason why the installer code block was creating the probel of ERROR 1053. Below is the installer code:
/* A console program that installs our skeleton service */ /* Author :- Nishant S */ /* EMail :- nish@inapp.com */ #include #include #include void ShowErr(); int main(int argc, char* argv[]) { SC_HANDLE NishService,scm; scm=OpenSCManager(0,0,SC_MANAGER_CREATE_SERVICE); if(!scm) { ShowErr(); return 1; } NishService=CreateService(scm,"PointHDListener", "PointHDListener Service", SERVICE_ALL_ACCESS,SERVICE_WIN32_OWN_PROCESS,SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL, "D:\\Service1.exe", 0,0,0,0,0); if(!NishService) { CloseServiceHandle(scm); ShowErr(); return 1; } CloseServiceHandle(NishService); CloseServiceHandle(scm); return 0; } void ShowErr() { //cout << "Error" << "\r\n"; }
thanks worked installer should be seperated from service manoj kulkarni Net protector antivirus