i like to know that when we start & stop win service programmatically from another apps then how could i pass some parameter to windows service programmatically....is it possible.
here is my sample code which i use to start service programmatically.
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;
}