/// <summary> /// Gets a service with the specified name. /// </summary> /// <param name="name">The unique name of the service.</param> public static Service FromName(string name) { Service svc; if (!ServiceCache.TryGetValue(name, out svc)) { svc = new Service(name); ServiceCache.Add(name, svc); } return svc; }
/// <summary> /// Gets a collection of all services on the local computer. /// </summary> public static Service[] GetServices() { ServiceController[] origSvcs = ServiceController.GetServices(); var services = new Service[origSvcs.Length]; for (int i = 0; i < services.Length; ++i) { ServiceController svc = origSvcs[i]; bool newInstance; services[i] = FromServiceController(svc, false, out newInstance); if (!newInstance) svc.Dispose(); } return services; }
private static bool ServiceExists(Service svc) { try { // ReSharper disable once UnusedVariable bool temp = svc.IsRunning; } catch (InvalidOperationException) { return false; } return true; }