C# 如何在以编程方式运行时向windows服务传递某些参数
我想知道,当我们从另一个应用程序以编程方式启动和停止win服务时,我如何以编程方式将一些参数传递给windows服务……是否可能 下面是我用来以编程方式启动服务的示例代码C# 如何在以编程方式运行时向windows服务传递某些参数,c#,windows-services,C#,Windows Services,我想知道,当我们从另一个应用程序以编程方式启动和停止win服务时,我如何以编程方式将一些参数传递给windows服务……是否可能 下面是我用来以编程方式启动服务的示例代码 private const int RestartTimeout = 10000; private readonly ServiceController service; public Control(string serviceName, string computerName) { service = new
private const int RestartTimeout = 10000;
private readonly ServiceController service;
public Control(string serviceName, string computerName)
{
service = new ServiceController(serviceName, computerName);
}
public Control(string serviceName)
{
service = new ServiceController(serviceName);
}
public bool StartService()
{
try
{
service.Refresh();
if (service.Status == ServiceControllerStatus.Stopped)
{
service.Start();
return true;
}
MessageBox.Show(string.Format("{0} --> already started", service.DisplayName));
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), @"Error Starting Service");
}
return false;
}
好,
我认为这是可能的,但是,我认为这只能以不同的方式来实现,因为ServiceController(以及通常的Windows服务)不接受参数
我的猜测是:
您的应用程序将收到一个参数数组,您可以对其进行处理。
ServiceController.Start()
方法有一个重载,该重载接受一个字符串数组作为参数,这些参数可以进一步实现。看