Announcement

Collapse
No announcement yet.

Problem when i execute sc start service

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem when i execute sc start service

    Hi,
    I tried to create one service 'BOEV5Service'; First I added the details in registry;
    After that When i execute "sc create BOEV5Service binpath = C:\BOEV5SERVER\intel_a\code\bin\BOEV5Service.exe" , i got "[SC] CreateService SUCCESS" message.
    When i try to execute "sc start BOEV5Service", i got error "[SC] StartService FAILED 1053: The service did not respond to the start or control request in a timely fashion".. Can anyway help me in this?

  • #2
    Originally posted by muthu kumar View Post
    Can anyway help me in this?
    Do you mean that you have written a service using PB Win compiler and it doesn't work? If so, posting source code might help.

    Comment


    • #3
      Hi Muthu;

      I agree with Chris. Please post a compileable code snippet that demonstrates the problem.

      Here are a couple of things to check:
      Is BOEV5Service.exe actually located at: C:\BOEV5SERVER\intel_a\code\bin\BOEV5Service.exe" ?

      Does BOEV5Service.exe launch if you double click it?

      Comment


      • #4
        Is is best not to just add the details to the registry. You should be using the API to install the service. The only thing you need the registry for is after you add your service to add the Description field since the API doesn't add it. I process a commandline with mine to install it. Your error also sounds like you may not be handling messages from the Service Manager.

        Code:
        '------------------------------------------------------------------------------
        '   ** Main Application Entry Point **
        '------------------------------------------------------------------------------
        Function WinMain(ByVal hInstance As Dword, ByVal hPrevInstance As Dword, ByVal lpCmdLine As Asciiz Ptr, ByVal iCmdShow As Long) As Long
        Local CmdParm             As String
        Local udtSTE              As SERVICE_TABLE_ENTRY
         
            '  Set the service name and display name here.
            gascServiceName             = "Service Template"
            gascServiceDisplayName      = "Service Template"
            gascServiceDesc             = "Description of Service"
            glnghInstance               = hInstance
         
            ' Get the Command Line parms
            CmdParm = UCase$(Extract$(@lpCmdLine, Any " ,." + Chr$(9)))
            ' Get rid of any seperators
            CmdParm = Remove$(CmdParm, Any "-\/")
         
            Select Case CmdParm
                Case "INSTALL" ' Install the service.
                    If IsFalse Install() Then
                        MsgBox "An error occured while trying to install this service", %mb_iconerror Or %mb_taskmodal, "Install Error"
                    Else
                        SetRegistryString(%HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Services\" + gascServiceName, "Description", gascServiceDesc)
                        MsgBox gascServiceDisplayName + " is now Installed", %mb_iconinformation Or %mb_taskmodal, "Install Completed"
                    End If
                Case "UNINSTALL" ' Uninstall the service.
                    If IsFalse Uninstall() Then
                        MsgBox "An error occured while trying to uninstall this service", %mb_iconerror Or %mb_taskmodal, "Uninstall Error"
                    Else
                        MsgBox gascServiceDisplayName + " is now Uninstalled", %mb_iconinformation Or %mb_taskmodal, "Uninstall Completed"
                    End If
                Case Else ' This should only happen when the service control manager starts us
                    udtSTE.lpServiceName = VarPtr(gascServiceName)
                    udtSTE.lpServiceProc = CodePtr(ServiceMain)
         
                    If StartServiceCtrlDispatcher(udtSTE) = 0 Then ' Failed to Start as Service, User most likely loaded EXE
                        MsgBox gascServiceDisplayName + " is a Service. Please Start it as such, or use /Install and /Uninstall for Addition/Removal of Service Entries.", %mb_iconerror Or %mb_taskmodal, "Service Start Error"
                    End If
            End Select
        End Function
         
        ' Install the service into windows
        Function Install() As Long
            Local lngHSCManager                   As Long
            Local lngHService                     As Long
            Local ascEXE                          As Asciiz * %MAX_PATH
         
            lngHSCManager = OpenSCManager(ByVal %Null, ByVal %Null, %SC_MANAGER_CREATE_SERVICE)
         
            If lngHSCManager <> %NULL Then
                '  OK, we have a handle to the SCM.
                '  Get the full EXE file path.
                If GetModuleFileName(glnghInstance, ascEXE, %MAX_PATH) <> 0 Then
                    '  Install the service.
                    lngHService = CreateService(lngHSCManager, gascServiceName, gascServiceDisplayName, _
                                                %My_Service_Rights, %SERVICE_WIN32_OWN_PROCESS Or %SERVICE_INTERACTIVE_PROCESS, _
                                                %SERVICE_AUTO_START, %SERVICE_ERROR_NORMAL, ascEXE, ByVal %Null, ByVal %Null, _
                                                ByVal %Null, ByVal %Null, ByVal %Null)
                    '  Close any service handles.
                    If lngHService <> %NULL Then
                        '  Success!
                        Function = %TRUE
                        StartService(lngHService, 0, 0)
                        CloseServiceHandle(lngHService)
                    End If
                End If
                CloseServiceHandle(lngHSCManager)
            End If
        End Function
         
        ' Unistall the service
        Function Uninstall() As Long
            Local lngHSCManager As Long
            Local lngHService   As Long
            Local srvcStatus    As SERVICE_STATUS
         
            lngHSCManager = OpenSCManager(ByVal %Null, ByVal %Null, %SC_MANAGER_CREATE_SERVICE)
         
            If lngHSCManager <> %NULL Then
                ' OK, we have a handle to the SCM.
                ' Now open our service.
                lngHService = OpenService(lngHSCManager, gascServiceName, %SERVICE_ALL_ACCESS Or &H00010000) ' &H00010000= %DELETE
                If lngHService <> %Null Then
                    ' See if Service Needs Stopped
                    If QueryServiceStatus(lngHService, srvcStatus) Then
                        If srvcStatus.dwCurrentState <> %SERVICE_STOPPED Then ' Stop service
                            ControlService(lngHService, %SERVICE_CONTROL_STOP, srvcStatus)
                        End If
                    End If
                    ' Delete the service.
                    If DeleteService(lngHService) <> %NULL Then
                        ' Success!
                        Function = %TRUE
                    End If
                    CloseServiceHandle lngHService
                End If
                CloseServiceHandle lngHSCManager
            End If
        End Function
        sigpic
        Mobile Solutions
        Sys Analyst and Development

        Comment


        • #5
          In ServiceMain you then need to register your message handler with RegisterServiceCtrlHandler and within it you need to process messages. ServiceMain then runs your code and/or waits for the service to be stopped using one of the Wait API calls that your handler can set when it receives a Stop command from the SCM. I showed a Modal Window in my ServiceMain and handle processing the Close of the window to stop the service, etc too. Hence the %SERVICE_INTERACTIVE_PROCESS flag in Install that you may not need if no GUI for it. Interactive I never could get to work well though and get beeps on shutdown because of the way Windows closes apps and shuts down services. I would stick with non-interactive for most needs.
          sigpic
          Mobile Solutions
          Sys Analyst and Development

          Comment

          Working...
          X