更新时间:2021-10-16 22:46:12
您可以使用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;