Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SC to install a windows service and then set recovery properties

I want to set the Recovery Options on a Windows Service I'm installing on a Windows Server 2003. I know this is possible to do manually, but I want to set the Recovery configuration when I install the service.

I use SC script to do this:

SC create MyService displayname= "MyService" binpath= "C:\Program Files\MyService\MyService.exe" start= auto  SC failure MyService reset= 86400 actions= restart/1000/restart/1000/run/1000  SC failure MyService command= "C:\Program Files\Myservice\MyService.exe" 

The problem is when the first whitespace is hit, it cuts off the path and takes the rest of the path as input parameters:

screendump here

So... in the properties dialog for the service (run -> services.msc -> right-click MyService -> Properties -> Recovery tab) I select "Subsequent failures -> Run a Program

As you can see I have put "" around the path in the command. How do I get to make whitespaces in the path? I know I can just make a path with no whitespaces, but that's not the point :-)

like image 216
user2110298 Avatar asked Feb 26 '13 09:02

user2110298


People also ask

What does the SC command do?

The SC command communicates with the Windows Service Controller and installed services. When used with its create command option, you can use it to create a Windows service under which the Endeca Server will run.

How do I run a SC exe service?

The name must use the Universal Naming Convention (UNC) format (for example, \myserver). To run SC.exe locally, don't use this parameter. Specifies the service name returned by the getkeyname operation. Specifies the service type.

How do I install the same Windows service with a different name?

In case you need the same service running on the same host but with different configuration, logically you would use same code just copy the service folder with different configuration and use installutil to install service with a different name.


1 Answers

This syntax seems to work:

sc failure MyService command= "\"c:\program files\myservice\myservice.exe\"" 
like image 156
Harry Johnston Avatar answered Oct 15 '22 17:10

Harry Johnston