Ejemplo n.º 1
0
 private bool IsServiceEnabled(string serviceName)
 {
     if (String.IsNullOrWhiteSpace(serviceName))
     {
         throw new ArgumentNullException(nameof(serviceName));
     }
     using (var service = new ServiceEditor(serviceName))
     {
         return(service.IsServiceEnabled() &&
                service.IsServiceRunAsLocalSystem());
     }
 }
Ejemplo n.º 2
0
        public bool EnableService(string serviceName)
        {
            if (string.IsNullOrWhiteSpace(serviceName))
            {
                throw new ArgumentNullException(nameof(serviceName));
            }
            RemoveWu10FromFileName(serviceName);
            var enabledRealtime = false;

            using (var service = new ServiceEditor(serviceName))
            {
                if (!service.IsServiceRunAsLocalSystem())
                {
                    service.SetAccountAsLocalSystem();
                }
                enabledRealtime = service.EnableService();
            }
            return(enabledRealtime);
        }