Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Getting problem in writing windows service [ ERROR 1053 ] [modified]

Getting problem in writing windows service [ ERROR 1053 ] [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
helpcsharpvisual-studio
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Soumyadipta
    wrote on last edited by
    #1

    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);

    R S 3 Replies Last reply
    0
    • S Soumyadipta

      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);

      R Offline
      R Offline
      Rajkumar R
      wrote on last edited by
      #2

      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^]

      1 Reply Last reply
      0
      • S Soumyadipta

        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);

        S Offline
        S Offline
        Soumyadipta
        wrote on last edited by
        #3

        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.

        I 1 Reply Last reply
        0
        • S Soumyadipta

          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.

          I Offline
          I Offline
          Iain Clarke Warrior Programmer
          wrote on last edited by
          #4

          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.

          S 1 Reply Last reply
          0
          • I Iain Clarke Warrior Programmer

            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.

            S Offline
            S Offline
            Soumyadipta
            wrote on last edited by
            #5

            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"; }

            N 1 Reply Last reply
            0
            • S Soumyadipta

              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);

              S Offline
              S Offline
              Soumyadipta
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0
              • S Soumyadipta

                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"; }

                N Offline
                N Offline
                netprotector
                wrote on last edited by
                #7

                thanks worked installer should be seperated from service manoj kulkarni Net protector antivirus

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups