Checking if a service is running in C#
Dec 13 2008 · .NET Platform
Surprisingly easy. I’m doing some bluetooth stuff and needed a way to see if the bluetooth support service (BthServ) was running before attempting bluetooth related system queries and socket IO.
ServiceProcess.ServiceController sc = new ServiceProcess.ServiceController("BthServ");
if (sc.Status != ServiceProcess.ServiceControllerStatus.Running)
// service not running
// service name not recognized