使用SC安装Windows服务,然后设置恢复属性 [英] Using SC to install a windows service and then set recovery properties

查看:1579
本文介绍了使用SC安装Windows服务,然后设置恢复属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Windows服务上设置恢复选项我在Windows Server 2003上安装。我知道这可以手动进行,但是我想在安装服务时设置恢复配置。



我使用SC脚本执行此操作:

  SC创建MyService displayname = MyServicebinpath =C:\Program Files\MyService\MyService.exestart = auto 

SC故障MyService reset = 86400 actions = restart / 1000 / restart / 1000 / run / 1000

SC失败MyService command =C:\Program Files\Myservice\MyService.exe

问题是当第一个空格被击中时,它切断路径并将其余路径作为输入参数:



< img src =https://i.stack.imgur.com/Wg0MG.pngalt =screendump here>



所以...在属性对话框中对于服务(运行 - > services.msc - >右键单击MyService - >属性 - >恢复选项卡)我选择后续失败 - >运行程序 p>

正如你所看到的,我在命令中的路径上放了。如何让路径中的空白?
我知道我可以做一个没有空格的路径,但这不是重点: - )

解决方案

语法似乎工作:

  sc失败MyService command =\c:\program files\myservice\myservice .exe \


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

解决方案

This syntax seems to work:

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

这篇关于使用SC安装Windows服务,然后设置恢复属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆