sc.exe to install an exe as a service?

15,451

Solution 1

You can't just run any executable as a service; The executable needs to be written specifically to incorporate a service loop. The service loop recieves control requests (eg. start, stop, restart, suspend) and must perform processing such as initialisation for start, cleanup for stop, etc and respond to those control requests, otherwise the service control manager will kill it.

Solution 2

Try to use

C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe Assembly.exe|dll

instead.

Share:
15,451
KJ3
Author by

KJ3

Updated on June 04, 2022

Comments

  • KJ3
    KJ3 almost 2 years

    I've been spending a lot of time reading about the sc.exe to run an executable as a Windows Service and it seems it should be fairly straighforward bu I'm having some issues get it to work without this error: error 1053 the service did not respond or control request in a timely fashion.

    I get the service to install and it is in the list of services but it is not allowing me to start it. This is what I'm using just a basic attempt:

    >sc create TestService binPath= "C:\Program Files (x86)\[path.exe]" DisplayName= "TestingServices" start= auto
    

    What am I doing wrong? Does my exe that I'm trying to run as a service have to be setup to properly be run as a service? I don't think that's the case because there are programs out there that can run any exe as a service. I'm trying to do the same, how can I do this?

  • KJ3
    KJ3 about 11 years
    There's no way to make an exe that's not designed to be a service run as a service in the background? I know it's possible because there are programs out there that do it, but I imagine it's a little more complicated that just running it like I was trying to do. Is there a simple way to run an exe that's not designed to be a service as a service (just something to keep it always running).
  • autistic
    autistic about 11 years
    Running as a service implies that it's designed to respond to service control requests. Have you ever seen an exe that's not designed to respond to service control requests, that's designed to respond to service control requests? Think carefully about your question. Don't ask X because X seems to be the way to do Y. Ask Y... Presuming you have the source code for this, implementing a service main isn't difficult. Have you tried?