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

你说的曾经没有我的故事 提交于 2019-11-28 22:05:50

问题


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:

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 :-)


回答1:


This syntax seems to work:

sc failure MyService command= "\"c:\program files\myservice\myservice.exe\""


来源:https://stackoverflow.com/questions/15085856/using-sc-to-install-a-windows-service-and-then-set-recovery-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!