0
我有一个Windows窗体应用程序,我不知道如何从该应用程序修改Windows服务。 此应用程序的Windows窗体将为此Windows服务配置一些参数。从Windows窗体应用程序创建Windows服务
例如: 可能有一个按钮可以用一些参数设置此Windows服务。
感谢,
罗德里戈
我有一个Windows窗体应用程序,我不知道如何从该应用程序修改Windows服务。 此应用程序的Windows窗体将为此Windows服务配置一些参数。从Windows窗体应用程序创建Windows服务
例如: 可能有一个按钮可以用一些参数设置此Windows服务。
感谢,
罗德里戈
您可以使用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);
嗨,步骤哪里的服务名? – 2014-09-23 01:37:15
如果你知道服务名称,那么你可以给service.ServiceName,否则给出Services.msc中出现的service.DisplayName。注意:DisplayName和ServiceName是不同的。 – 2014-09-23 01:41:38
在我的情况下,服务已经存在。我停止服务并使用新参数重新启动服务。 – 2014-09-23 01:41:40