Error 1053 the service did not respond to the start or control request in a timely fashion

257,738

Solution 1

In my case, I was publishing service while it was in debug mode.

Solution was:

  • Changing solution to release mode
  • Uninstall old service with command InstallUtil -u WindowsServiceName.exe
  • installing service again InstallUtil -i WindowsServiceName.exe

It worked perfectly after.

Solution 2

As others have pointed out, this error can have a multitude of causes. But in the hopes that this will help somebody out, I'll share what happened in our case. For us, our service had been upgraded to .NET 4.5, but the server did not have .NET 4.5 installed.

Solution 3

After spending some time on the issue, trying solutions that didn't work, I run into this blog. It suggests to wrap the service initialization code in a try/catch block, like this, and adding EventLog

using System;
using System.Diagnostics;
using System.ServiceProcess;

namespace WindowsService
{
    static class Program
    {
        static void Main()
        {
            try
            {
                ServiceBase[] ServicesToRun;
                ServicesToRun = new ServiceBase[] 
                { 
                    new Service1() 
                };
                ServiceBase.Run(ServicesToRun);
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry("Application", ex.ToString(), EventLogEntryType.Error);
            }
        }
    }
}

Then, uninstall the old service, redeploy the service with these modifications. Start the service and check out the Event Viewer/Application logs. You'll see what the real problem is, which is the underlying reason for the timeout.

Solution 4

I encountered the same issue and was not at all sure how to resolve it. Yes this occurs because an exception is being thrown from the service, but there are a few general guidelines that you can follow to correct this:

  • Check that you have written the correct code to start the service: ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new WinsowsServiceToRun() }; ServiceBase.Run(ServicesToRun);
  • You need to ensure that there is some kind of infinite loop running in the class WinsowsServiceToRun

  • Finally, there may be some code which is not logging anything and closing the program abruptly (which was the case with me), in this case you will have to follow the old school of debugging which needed to write a line to a source (text/db/wherever). What I faced was that since the account running the service was not "Admin", the code was just falling off and not logging any exceptions in case it was trying to write to "Windows Event Log" even though the code was there to log exceptions. Admin privilege is actually not needed for logging to Even Log but it is needed to define the source. In case source of the event is not already defined in the system and the service tries to log it for the first time without admin privilege it fails. To solve this follow below steps:

    1. Open command prompt with admin privilege
    2. Paste the command : eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO <<Source>> /D "<<SourceUsingWhichToWrite>>"
    3. Press enter
    4. Now start the service

Solution 5

I have just tried this code locally in .Net 4.5 and the service starts and stops correctly for me. I suspect your problem may be around creating the EventLog source.

The method:

EventLog.SourceExists("MySource")

requires that the user running the code must be an administrator, as per the documentation here:

http://msdn.microsoft.com/en-us/library/x7y6sy21(v=vs.110).aspx

Check that the service is running as a user that has administrator privileges.

Share:
257,738
Neeraj Verma
Author by

Neeraj Verma

Updated on July 05, 2022

Comments

  • Neeraj Verma
    Neeraj Verma almost 2 years

    I have created and installed a service a couple of times. Initially it was working fine, but after some changes in the service Code it start giving the error when I restart the service in Services.msc :

    Error 1053: the service did not respond to the start or control request in a timely fashion

    Code:

    public partial class AutoSMS : ServiceBase
    {
        public AutoSMS()
        {
            InitializeComponent();
            eventLog1.Clear();
    
            if (!System.Diagnostics.EventLog.SourceExists("MySource"))
            {
                System.Diagnostics.EventLog.CreateEventSource(
                    "MySource", "MyNewLog");
            }
            eventLog1.Source = "MySource";
            eventLog1.Log = "MyNewLog";
    
            Timer checkForTime = new Timer(5000);
            checkForTime.Elapsed += new ElapsedEventHandler(checkForTime_Elapsed);
            checkForTime.Enabled = true;
    
        }
    
        protected override void OnStart(string[] args)
        {
            eventLog1.WriteEntry("In OnStart");
        }
    
        protected override void OnStop()
        {
            eventLog1.WriteEntry("In onStop.");
        }
    
    
        void checkForTime_Elapsed(object sender, ElapsedEventArgs e)
        {
            string Time = "15:05:00";
            DateTime dateTime = DateTime.ParseExact(Time, "HH:mm:ss",
                                            CultureInfo.InvariantCulture);
    
            if (DateTime.Now == dateTime) ;
                eventLog1.WriteEntry(Time);
        }
    }
    

    Here is my main method code

    static void Main()
    {
        ServiceBase[] ServicesToRun;
        ServicesToRun = new ServiceBase[] 
        { 
            new AutoSMS() 
        };
        ServiceBase.Run(ServicesToRun);
    }
    

    I also tried the following steps :

    • Go to Start > Run > and type regedit
    • Navigate to: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control
    • With the control folder selected, right click in the pane on the right and - select new DWORD Value
    • Name the new DWORD: ServicesPipeTimeout
    • Right-click ServicesPipeTimeout, and then click Modify
    • Click Decimal, type '180000', and then click OK
    • Restart the computer

    I used to install and uninstall it with following command :

    installutil AutoSMS.exe
    
    installutil /u AutoSMS.exe
    
  • Neeraj Verma
    Neeraj Verma almost 10 years
    I started the service.msc with administrator account and also tried to install and uninstall service.exe with command prompt as RUn as Administrator ...Still it is not working
  • devduder
    devduder almost 10 years
    You need to check to see what account the actual service is running under, rather than running the command prompt to install the service as an admin. In Services, right click on the AutoSMS service and select Properties -> Log On tab. Try selecting the top radio radio button for Local System account
  • BlueRaja - Danny Pflughoeft
    BlueRaja - Danny Pflughoeft about 9 years
    I encountered the exact same problem and solution. I'm not sure why this works, but thank you!
  • Anand Rajan
    Anand Rajan almost 9 years
    i am facing same problem but not in all systems. i have created a windows service. its running fine most of the system. in couple of systems alone i am facing this error 1503. i tried regedit, cmd window- event. no use!
  • Burak Karakuş
    Burak Karakuş almost 9 years
    did you try removing these parts from the specific systems .config file?
  • Anand Rajan
    Anand Rajan almost 9 years
    i dont have such lines"cachingConfiguration" in my .config file. i am trying to install .net 4.5 framework in those systems. it is downloading
  • Burak Karakuş
    Burak Karakuş almost 9 years
    oh, I see. sorry, I don't know how it is resolved. :/
  • Anand Rajan
    Anand Rajan almost 9 years
    i used install shield le to generate setup file for this windows service. when i was developing this windows service from my system which has VS2012. .net framework 4.5. i assumed that this service requires min .net framework 4.0. when i install in other system which has .net 4.0 may caused this issue. i am not anand, i am pranesh.
  • Anand Rajan
    Anand Rajan almost 9 years
    i got the solution for error 1503. The issue is .net framework version. my service required .net framework 4.5 but in system it was 4.0. so the service start issued the error 1503. now rectified!! some one shall get a clue for their problem from this! thanks all
  • Anand Rajan
    Anand Rajan almost 9 years
    .net framework version is the key for the solution. nothing else. i replaced .net framework 4.0 with 4. 5 after that service started without any issues.
  • mkb
    mkb almost 9 years
    nice answer, in my case the problem is ServiceBase.Run(ServicesToRun); line is never accessed. since the service is also designed so it can run in command line I missed the conf. one missed configuration and wasted hours...
  • Akash Sahay
    Akash Sahay almost 9 years
    @mkb: Yes a miss config does take out a lot of time. Out of the above mentioned I faced two and took me hours to figure the same. Thanks for upvoting and the edit.
  • John
    John over 7 years
    @mkb What config do you mean?
  • mkb
    mkb over 7 years
    @abatonime at that time I added a key to the app.config to decide whether it will run as windows service or as a common CommandLine program. something like runasservice="true" and when I set it to false ServiceBase.Run(ServicesToRun); is never called
  • John
    John over 7 years
    @mkb OK thanks. In my case I used System.Diagnotstics.Debugger.Launch() to start debugging in VS and found out there was an exception thrown because the CurrentDirectory is set to windows/system32
  • mkb
    mkb over 7 years
    @Abatonime well done, I can feel it, damn directory errors :)
  • cameronjchurch
    cameronjchurch over 7 years
    Man I scratched my head on this for a while. Checking config files and event logs to no end until I read this answer and kicked myself for forgetting to flip the build to release. This worked for me!
  • Rubenisme
    Rubenisme over 7 years
    I was fixing a service for a coworker, unfortunately in debug build it didn't call the ServiceBase.Run method, just called the method for processing directly. #if !DEBUG should be used sparingly.
  • Tim B James
    Tim B James over 7 years
    Multitude is correct. The error could appear if you have errors within your service. So related to your code rather than the framework.
  • RBT
    RBT about 7 years
    By extra symbols you means additional settings or invalid junk characters (which makes the xml structure invalid)? Can you please share the details about then in your answer.
  • Faizan Mubasher
    Faizan Mubasher over 6 years
    When I commented out EventLog thing, my service started working. But I need EventLog though I ran command prompt as an Administrator. I think running command prompt as an Admin doesn't fix the problem.
  • it3xl
    it3xl almost 5 years
    Problem signature: P1: YourServiceName.exe ... P4: System.Configuration ... P9: System.TypeInitialization
  • Dave
    Dave almost 5 years
    Around the topic of .NET - we received this message because our windows service was running on .NET 2.0, when we moved it onto a Windows 2019 instance (which didn't have .NET 2.0 installed), we got this error. It took us a full day to figure this one out - so hope this can help someone else out.
  • RahulGo8u
    RahulGo8u almost 5 years
    This worked for me as well. Was releasing the DLLs using debug mode encountered the issue. After building solution using release mode. It worked perfectly.
  • Inphinite Phractals
    Inphinite Phractals almost 5 years
    I had 4.5 installed but was missing the 4.5.2 update.
  • Alexandra
    Alexandra over 4 years
    Tacking on that in my case, the flavor of cause for this error was that the EXE was not implementing ServiceBase OnStart or OnStop
  • Jobert Enamno
    Jobert Enamno over 4 years
    Thanks this saved me hours! In my case the missing part is ServiceBase.Run(ServicesToRun);. It was commented.
  • Piero Alberto
    Piero Alberto over 4 years
    Good idea but in my case it doesn't log anything.. still this annoying message and no hints about it!
  • mihkov
    mihkov over 3 years
    Yees, that's the issue that I had. But to realize details of the problem, you can check Event viewer > Windows Logs > Application. There was the stacktrace helped me to update the config file.
  • Yuriy Ivaskevych
    Yuriy Ivaskevych over 3 years
    The important part here is .UseWindowsService() should be called LAST (right before .Build()). Thanks!
  • Ben Seymour
    Ben Seymour over 2 years
    This is still a relevant answer. Some of our services stopped working after an in-place upgrade to Server 2016. Installing a missing .NET Framework runtime (4.7.2 in our case) got them working again.