使用 SC 安装 Windows 服务,然后设置恢复属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15085856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using SC to install a windows service and then set recovery properties
提问by user2110298
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.
我想在 Windows Server 2003 上安装的 Windows 服务上设置恢复选项。我知道这可以手动完成,但我想在安装服务时设置恢复配置。
I use SC script to do this:
我使用 SC 脚本来做到这一点:
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
所以...在服务的属性对话框中(运行 -> services.msc -> 右键单击 MyService -> 属性 -> 恢复选项卡)我选择“后续故障 -> 运行程序
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 :-)
如您所见,我在命令中的路径周围放置了“”。如何在路径中创建空格?我知道我可以创建一条没有空格的路径,但这不是重点:-)
采纳答案by Harry Johnston
This syntax seems to work:
这种语法似乎有效:
sc failure MyService command= "\"c:\program files\myservice\myservice.exe\""