Currently I\'m checking it in the following way:
if (Environment.UserInteractive)
Application.Run(new ServiceControllerForm(service));
else
ServiceBase.R
The issue with the accepted answer is that checking the status of an service that isn't installed will throw. The IsService
Method I'm using looks like this:
private bool IsService(string name)
{
if (!Environment.UserInteractive) return true;
System.ServiceProcess.ServiceController sc = new System.ServiceProcess.ServiceController(name);
try
{
return sc.Status == System.ServiceProcess.ServiceControllerStatus.StartPending;
}
catch(InvalidOperationException)
{
return false;
}
}
Which should work more reliably than just checking Environment.UserInteractive