我想知道,当我们以编程方式从另一个应用程序启动和停止 win 服务时,我如何以编程方式将一些参数传递给 Windows 服务....有可能吗?
这是我用来以编程方式启动服务的示例代码。
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;
}