如何获取Windows服务的当前设置。 [英] How to get current settings of a windows service.
本文介绍了如何获取Windows服务的当前设置。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个名为XYZ的Windows服务。我可以将其属性设置为启动类型和恢复。我的问题是如何获取其当前设置。
我想得到它的
1.启动类型
2.Recovery
2.1首次失败
2.2第二次失败
2.3后续失败
I have created a windows service say XYZ. I could set its properties that is "startup type" and the "recovery".My question is how to get its current settings.
I want to "get" its
1.Startup Type
2.Recovery
2.1 First failure
2.2 Second failure
2.3 Subsequent failure
推荐答案
您可以使用sc [ ^ ]。
一个简单的例子是通过命令字符串设置失败选项 -
You can set properties using sc[^].
A simple example would be setting failure option via a command string -
var startInfo = process.StartInfo;
startInfo.FileName = "sc";
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
// tell Windows that the service should restart if it fails
startInfo.Arguments = string.Format("failure \"{0}\" reset= 0 actions= restart/60000", serviceName);
process.Start();
process.WaitForExit();
exitCode = process.ExitCode;
这篇关于如何获取Windows服务的当前设置。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文