从Windows窗体应用程序创建Windows服务

时间:2014-09-23 00:33:04

标签: c# winforms

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

实施例: 可以有一个按钮,可以使用一些参数设置此Windows服务。

谢谢,

罗德里戈

1 个答案:

答案 0 :(得分:2)

您可以通过使用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);