2

I was supposed to convert a GoLang compiled file .exe as a service in windows but as the service was executed with 9 parameters from outside so I decided to use SC to make the .exe as a service and my syntax was ,

sc create myservice binPath= "\"PATH\file.exe\" -param1=value -param2=value -param3=value...-param9=value" displayname= "MyServer"  start= auto

the service created successfully but when I try to start it, it fails with "service did not respond in a timely fashion" ..

But When I created the same service with nssm syntax ,

nssm install myservice "PATH\file.exe" -param1=value -param2=value -param3=value...-param9=value

It was working and I was getting response from my service , I don't know whether the problem is with the syntax in SC or my service...

I even tried many possible ways like removing \" and giving parameters directly like binPath= "PATH/file.exe -param1=value -param2=value...param9=value" but it didn't work and I also tried to pass the parameters inside quotes , It didn't work either :( Any help would be appreciated.

Kamikaze
  • 23
  • 1
  • 8
  • We'll need to see the code. – Harry Johnston Jun 29 '16 at 02:29
  • well @HarryJohnston I can't post the code for some reasons , But I can say the process happening in the code . It fetches the CPU usage of the machine and sends it to an application with the help of HTTP POST. The Application needs unique data which I need to give for each machine where I run , So I gave them(unique data's) as external parameters (9 param's) which is sent along the CPU usage in POST.. For every 10 minutes its POST'ed and the response status is logged in a log file ... – Kamikaze Jun 29 '16 at 10:30
  • The problem is unlikely to be anything to do with what the service is intended to do, so that doesn't really help. Error 1053 happens when the executable fails to call StartServiceCtrlDispatcher, or doesn't do so quickly enough. From the looks of it you do that in Go by calling the `Run` function from the `golang.org/x/sys/windows/svc` package. Perhaps your main function is exiting without ever calling `Run` because it doesn't like the parameters it was given? – Harry Johnston Jun 29 '16 at 21:36
  • @HarryJohnston Thanks for the Point Bro , But there is nothing to with svc package I guess as it only handles the one which is already a service .. What I am trying to do here to just convert an exe to service manually, not from GO.. And Yes it looks like sc doesn't like the parameters given to it .. – Kamikaze Jun 30 '16 at 09:31
  • 1
    You've said that `sc` works for your other executables, so those executables must be using the svc package or some equivalent. **You cannot use sc directly on an executable that was not built to be a service. This doesn't work, ever.** (Of course, you can use `sc` *indirectly*, by pointing it at `srvany.exe` or `nssm.exe` or equivalent.) – Harry Johnston Jun 30 '16 at 21:10
  • Please copy and paste the output of `sc qc myservice` for both the service that isn't working and for one of the services that is. (It might also be useful for you to compare and contrast the output of `sc qc` when you install the service with `sc` with when you install it with `nssm`.) – Harry Johnston Jun 30 '16 at 21:11
  • @HarryJohnston thanks for the command ... still the nssm shows the binpath as only its C:\test\nssm.exe but not with parameters .. where my binpath is the one which I gave with paramerters (C:\test\myapp.exe -param1=xx -param2=xxx ..)and so .. – Kamikaze Jul 27 '16 at 06:02
  • And still I didn't get the proper solution for that problem ... Sad life :'( – Kamikaze Jul 27 '16 at 06:07

1 Answers1

4

While SC will happily install any executable as a windows service, it should only be used to install executables that are already Windows Services. If you use SC to install a regular exe, your service will fail with Error 1053 when you try to start it. Your Go exe, which does not implement the Windows Service interface, falls victim to this situation.

CoreTech
  • 2,345
  • 2
  • 17
  • 24
  • But I have done with other .exe's which are compiled using GO and they were working fine with SC .. only this .exe which is with 9 parameters struggling to start, and from your statement " it should only be used to install executables that are already Windows Services" , can you explain it ? – Kamikaze Jun 28 '16 at 13:23
  • Note that `nssm` can't be used to install actual services, it is used to run arbitrary applications *as if* they were services. If both `nssm` and `sc` work, your executable is being excessively clever and running either as a service or as an application depending on how you start it. – Harry Johnston Jun 29 '16 at 02:31
  • Thanks for the info , But I seriously can't get the difference from a service and exe.. from the internet I possibly understood that service is an exe under Service manager surveillance and a normal exe is under windows manager surveillance... I m still not clear though as both of them are executing ... Need to learn more .. – Kamikaze Jun 29 '16 at 10:48
  • Are you sure that your other Go applications work properly as windows services? When started, they don't throw up error #1053? – CoreTech Jun 29 '16 at 13:48
  • 1
    @Kamikaze: a normal application doesn't have to call windows manager functions unless it actually wants to present a window, but a service application *has* to call service control manage functions (such as StartServiceCtrlDispatcher) in order to run properly. If it doesn't, the service control manager decides that it has hung and terminates it. – Harry Johnston Jun 29 '16 at 21:38
  • @CoreTech Yes it does work properly and I m running another application with that .. – Kamikaze Jun 30 '16 at 09:19