19

I have two binaries and have to create a service for them. I tried a solution using "sc create" from How to install a Windows service with Inno Setup?

But it did not work for me. It's getting stuck at the end of the installation. What am I doing wrong?

Here is my code:

Filename: {cmd}; Parameters: "sc create srvname start= auto DisplayName= mysrv binPath= {app}\mybinary.exe" ; Flags: runhidden

I tried using cmd instead of {cmd} - no change.

I did not try the Pascal code in the solution which I referred. I am keeping it as the last resort.

Community
  • 1
  • 1
rgm
  • 1,241
  • 2
  • 16
  • 33
  • 1
    possible duplicate of [How to install a Windows service with Inno Setup?](http://stackoverflow.com/questions/15204587/how-to-install-a-windows-service-with-inno-setup) – TLama May 13 '13 at 08:54
  • 1
    so you mean to tell that i have to use pascal code which is there in the solution you mentioned. – rgm May 13 '13 at 09:32
  • 2
    Not that you have to, just that you should. – TLama May 13 '13 at 09:40

2 Answers2

38

I used this code and both of my services are installing and uninstalling:

[run]
Filename: {sys}\sc.exe; Parameters: "create mysrv start= auto binPath= ""{app}\mysrv.exe""" ; Flags: runhidden

[UninstallRun]
Filename: {sys}\sc.exe; Parameters: "stop mysrv" ; Flags: runhidden
Filename: {sys}\sc.exe; Parameters: "delete mysrv" ; Flags: runhidden

This solved my problem, so why should I use Pascal in this case.?

Tomasz Stanczak
  • 12,796
  • 1
  • 30
  • 32
rgm
  • 1,241
  • 2
  • 16
  • 33
  • 13
    *Why should I use Pascal in this case ?* Because you can't handle or react on if something goes wrong with this script ? I know you don't care now, but soon or later you will. Your users might be surprised if you tell them the installation was successful and if they run the application expecting the service to be running the application fail because the service will be actually stopped, but you won't notice that failed attempt to service start in installer. – TLama May 13 '13 at 17:37
12

Is there any reason you're trying to run it through {cmd}?

Either add the /C parameter and quote the rest as required, or just run sc.exe with the required parameters.

[Run]
Filename: "sc.exe"; Parameters: "create srvname start= auto DisplayName= mysrv binPath= {app}\mybinary.exe" ; Flags: runhidden 

Note that the correct way to install the service is the API as mentioned in this answer that will allow you to detect and handle errors.

Community
  • 1
  • 1
Deanna
  • 23,876
  • 7
  • 71
  • 156
  • Is there any reason you're trying to run it through {cmd} ? Yes, it is another syntax viewed all over Internet. Do you mean `{sys]\sc.exe` is better than using an invisible `{cmd}` ? – Sandburg Mar 20 '19 at 08:40
  • @Sandburg of course. Why run an executable (with significant overhead) to run another executable, when you can just run that 2nd executable directly? – Deanna Mar 20 '19 at 09:45