Install a Service and error: windows could not start the service on local computer error 1053

This is how you add a new Service in Windows Server 2012 (or other windows versions for that matter) and how to find a solution for the error: windows could not start the service on local computer error 1053. There are three ways to create a service, let us take a look at the first two. Open up Windows Powershell and remember to start it as administrator. While there, run:

New-Service -Name "My Cool Program" -BinaryPathName "D:\CoolProgram\Release\TheProgram.exe"

Or run it in command prompt (CMD) like this, also like administrator:

sc.exe create "My Cool Program" binPath= "D:\CoolProgram\Release\TheProgram.exe"

If you need to delete your service use:

sc.exe delete "My Cool Program"

If you got this error: windows could not start the service on local computer error 1053. Then there could be a various kind of reasons for the problem. I have listed my solution to this problem below after trying basically everything.

Error from Event Viewer: <myprogram> service failed to start due to the following error:
The service did not respond to the start or control request in a timely fashion.

Check if these solve your issue:

  • Try install your service and start it with NSSM – the Non-Sucking Service Manager. This was the solution that worked for me. You download the program and open up CMD in that folder where you have NSSM unzipped, and then run:
nssm install

Then choose your file path and give it a name. Then start the service through the command:

nssm start "my name of service"

Other things you can check:

  • Check .NET version so that it is correct under your web/app configurations with what you are running on the server (this line)
<startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
  • Check so that you don’t publish your program with Debug mode, you should publish it with Release mode.
  • You can also try increasing the time that it takes before a Service stops trying to start: see this website for instructions. Probably not the issue though but who knows.
  • Check that you have all the assemblies/dependencies for your project.
  • You can try run everything in a try and catch block to catch the error (see from stackoverflow) (which did nothing for me):
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);
            }
        }
    }
}

0 0 votes
Article rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments