C# 从windows窗体应用程序创建windows服务

C# 从windows窗体应用程序创建windows服务,c#,winforms,C#,Winforms,我有一个windows窗体应用程序,我想知道如何从该应用程序修改windows服务。 此应用程序windows窗体将为此windows服务配置一些参数 例如: 可能有一个按钮,可以使用一些参数设置此windows服务 谢谢 Rodrigo您可以通过表单应用程序使用ServiceController类设置启动参数来启动服务,该类将在命名空间System.ServiceProcess下可用 ServiceController service = new ServiceController(); st

我有一个windows窗体应用程序,我想知道如何从该应用程序修改windows服务。 此应用程序windows窗体将为此windows服务配置一些参数

例如: 可能有一个按钮,可以使用一些参数设置此windows服务

谢谢


Rodrigo

您可以通过表单应用程序使用ServiceController类设置启动参数来启动服务,该类将在命名空间System.ServiceProcess下可用

ServiceController service = new ServiceController();
string[] args=new string[2];
args[0] = "Your first argument";
args[1] = "Your second argument";
service.DisplayName = "Your Service Display Name";//As it appears in services.msc
service.Start(args);

您好,步骤服务名称在哪里?如果您知道服务名称,那么您可以提供service.ServiceName,或者提供Services.msc中显示的service.DisplayName。注意:DisplayName和ServiceName是不同的。在我的例子中,服务已经存在。我停止服务并使用新参数再次启动它。