4

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.

8
  • We'll need to see the code. Commented Jun 29, 2016 at 2: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
    Commented Jun 29, 2016 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? Commented Jun 29, 2016 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
    Commented Jun 30, 2016 at 9: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.) Commented Jun 30, 2016 at 21:10

1 Answer 1

6

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.

6
  • 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
    Commented Jun 28, 2016 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. Commented Jun 29, 2016 at 2: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
    Commented Jun 29, 2016 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
    Commented Jun 29, 2016 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. Commented Jun 29, 2016 at 21:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.