1

I am trying to set multiple properties when creating a service using SC with Inno Setup I have not been able to get this to work 100% so far, I have got the service name, display name, dependencies and Description working correctly. It is just the Recovery settings i need to preset. (see image)

enter image description here

I have tried multiple ways of writing this, i have tried the failure and description part on the same line with single, double and tipple quotes non of them work i tried on a new line as below this doesn't work either. Unsure if they have to be in a specific order ?

I have look around and not found anything on setting Recovery settings an example is: Inno Setup: Installing Windows services using "sc create" Of course i have looked here too: https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-r2-and-2012/cc742069(v%3Dws.11) but i cant figure out how to translate it to inno script.

I know this is not the "correct way" to do this and its better to use pascal code or use these service scripts http://www.sandon.it/node/9 but i just want to understand this way for my own curiosity/education plus i haven't found any good examples of pascal code.

I do have the service script working with some pascal code by including it in the code section then using registry settings so set properties it does not support however i specifically want to know how to do the same just with SC.exe for my own education.

[Run]
Filename: {sys}\sc.exe; Parameters: "create SERVICENAME start= auto DisplayName= ""SERVICEDISPLAYNAME"" binPath=""{app}\SERVICEEXE.exe"" depend= mpssvc"; Flags: runhidden
Filename: {sys}\sc.exe; Parameters: "failure ""SERVICENAME"" reset= 100 actions= restart/1000/restart/1000"; Flags: runhidden
Filename: {sys}\sc.exe; Parameters: "description SERVICENAME ""SERVICE DESCRIPTION"""; Flags: runhidden


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

1 Answers1

1

This question is a bit old but I figured out the solution to set the SC FAILURE from the script and this may be useful for someone else.

The problem reported (recovery actions not being set) is caused by the flag set at the end of the command (runhidden). It will work fine if set waituntilidle or waituntilterminated. But the easiest solution is to remove the Flag because waituntilterminated is the default one.

Filename: "{sys}\sc.exe"; Parameters: "failure ""MyService"" reset= 86400 actions= restart/60000/restart/60000/restart/60000"

Another interesting thing is that reset expects to receive the time in minutes but the GUI shows days, so if the value is less than 84600 always will show 0 days.

The "restart service after" in the GUI is in minutes but in the command is in milliseconds so only shows something other than 0 if is greater than 60000.

The last thing is the way to set less than 3 failures, the action should be empty but needs some time defined.

actions= restart/15000/restart/30000//1000

That last point is explained on this post:
How to use "sc" to install a service and specify NO ACTION for "subsequent failures" under recovery

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992