5

I have an executable that I would like to set to run as a service. Using the sc.exe tool provided by windows (see KB article here: http://support.microsoft.com/kb/251192), I successfully "registered" the service. However, when I go to the Service Management Console (Start->Run->services.msc) and start the service, I get the following error:

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

After reading around my initial impression is that service executables have to conform to an API, and that among the required functions/methods a service has to respond to are a start/stop/restart command. However, this seems to defeat the whole point of the sc.exe tool which is advertised with the ability to turn any executable into a service.

Can anyone shed some light on this for me?

user1046592
  • 61
  • 1
  • 1
  • 2

3 Answers3

3

This is the code you are looking for:

sc create SERVICENAME binPath= "cmd /c c:\programlocation\program.exe" 

It will not rid you of error 1053, but at least this will apply to the console (CMD) who already did the job of running the app in the background (check task manager to confirm).

Aaron
  • 2,049
  • 4
  • 28
  • 35
brunobliss
  • 364
  • 1
  • 16
  • 1
    @davehale23, why did you enclose `cmd /c` within `** **`? is it just to emphasis or is it part of the code (don't think so...)? – aschipfl Jul 30 '15 at 18:12
  • 1
    I was shocked to discover that sc has NO VALIDATION. So you can any anything to services, very bad from Microsoft. sc create crap binpath="pile of crap" [SC] CreateService SUCCESS – Paul McCarthy Jun 13 '17 at 09:27
1

Take a look at Topshelf-project which turns many arbitrary executables into services.

When you reference Topshelf, you can run your exe from a command-line, or install it into Windows Services with:

your.exe install

Even with topshelf registered, you would still want to have a logging facility -- such as log4net -- to monitor bootstrapping activities that could prevent it from launching in a timely fashion.

Kurt Johnson
  • 411
  • 5
  • 15
  • Their web site is not very informative, but from what I can tell Topshelf appears to be intended to make it easier to write services in .NET, not to run an arbitrary executable as a service. If you don't (at a minimum) have the source code for the executable in question, I don't think Topshelf will help. – Harry Johnston Mar 10 '12 at 03:53
  • I would agree on the dearth of documenation on Topshelp. Although it's project life is past the nascent stage, it still lacks in tutorials and robust walk-throughs. Sorry that didn't get you closer. Good luck! – Kurt Johnson Mar 26 '12 at 14:30
-1

One very likely cause of this behavior is the application that is started is displaying a request for interaction with the end user (messagebox, input prompt, licensing dialog, etc). We have run into this more than once. This usually happens with applications that aren't designed to run as services. You could try running the service as Local System and check the Allow service to interact with desktop checkbox.

The other possibility is that the user the service is configured to run as doesn't have access to resources (disks, databases, etc). If the process works correctly interactively, then try changing the service's user credentials to your user and see if that gets you any further.

Update

Apologies, I assumed the question was regarding srvany which is the application you are looking for.

competent_tech
  • 44,465
  • 11
  • 90
  • 113
  • -1 sc.exe is not able to turn an arbitrary executable into a service, so both the question and this answer are based on a false assumption. – Harry Johnston Nov 15 '11 at 01:09
  • Sorry, didn't read the question closely enough; I had incorrectly assumed they were using srvany since that is what popped into my head as soon as I started reading the question. I have fixed my answer. – competent_tech Nov 15 '11 at 01:28