如何programically配置安装的Windows服务programically、Windows

2023-09-06 15:06:57 作者:哥哥别杀我

我有一个.net C#Windows服务应用程序,工作得很好,现在,妥善自行安装。 我也有一个小的WinForms工具提供了友好的界面来修改它的配置文件。

I have a .Net C# Windows service app that works nicely now, and installs itself properly. I also have a small WinForms tool to provide a friendly interface to modify its config file.

它发生,我认为一个很好的接触将扩展这个工具来配置服务本身,以及(您的服务管理工具做的东西,如启动模式,Windows登录帐户凭据等)。

It occurs to me that a nice touch would be to extend this tool to configure the service itself as well (the stuff you do in the Services admin tool, eg Startup mode, Windows login account credentials, etc).

这个问题能相对容易地与.NET Framework做了什么?我找不到任何引用到这个已经做了,但我想它可以。谁能指教?

Can this be done relatively easily with the .Net framework? I can't find any references to this having been done, but I imagine it can. Can anyone advise?

TIA

推荐答案

您可以通过完成大量的 服务控制器 类。它使启动/停止等。

You can accomplish a lot using the Service Controller class. It enables Starting/Stopping etc.

您可以通过调用你会使用控制台SC 工具以同样的方式做休息:

The rest you can do by calling the sc tool the same way you would using a console:

var process = Process.Start(
    "sc", 
    "failure \"ServiceName\" reset= 60 actions= restart/1000/restart/1000");
process.WaitForExit();
 
精彩推荐