using Microsoft.Win32; using System; using System.Collections.Generic; using System.ServiceProcess; using System.Linq; namespace VMwareLauncher { public class ServiceControl { public static readonly List VMwareServiceList = new List //Array of services to close { "VMnetDHCP", "VMUSBArbService", "VMware NAT Service", "VMwareHostd", "VMAuthdService" }; public bool ForceServicesManual() { bool errors = false; string winServices = @"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services"; try { foreach (var service in VMwareServiceList) { string currentService = winServices + "\\" + service; if ((int)Registry.GetValue(currentService, "Start", null) != 3) { Registry.SetValue(currentService, "Start", 3); } } } catch (Exception) { errors = true; throw; } return errors; } public List GetStoppedVmServices() { var stoppedVmServices = new List(); var services = ServiceController.GetServices(); foreach (var service in services) { if (service.Status == ServiceControllerStatus.Stopped && VMwareServiceList.Contains(service.ServiceName)) stoppedVmServices.Add(service.ServiceName); } return stoppedVmServices; } } }